Question

Can someone help me to understand what is wrong with the code below? The problem is inside the "join" method - I am not able to set "state" field. Error message is -

No implicit view available from code.model.Membership.MembershipState.Val => _14.MembershipState.Value.
[error]         create.member(user).group(group).state(MembershipState.Accepted).save
[error]                                                       ^
[error] one error found
[error] (compile:compile) Compilation failed

What does _14 mean? I tried similar thing with MappedGender and it works as expected, so why MappedEnum fails?

scala 2.10 lift 2.5

Thanks

package code
package model

import net.liftweb.mapper._
import net.liftweb.util._
import net.liftweb.common._


class Membership extends LongKeyedMapper[Membership] with IdPK {
  def getSingleton = Membership


  object MembershipState extends Enumeration {
   val Requested = new Val(1, "Requested")
   val Accepted = new Val(2, "Accepted")
   val Denied = new Val(3, "Denied")
  }

  object state extends MappedEnum(this, MembershipState)
  {
    override def defaultValue = MembershipState.Requested
  }

  object member extends MappedLongForeignKey(this, User) {
    override def dbIndexed_? = true
  }


  object group extends MappedLongForeignKey(this, Group) {    
    override def dbIndexed_? = true
  }

}

object Membership extends Membership with LongKeyedMetaMapper[Membership] {
    def join (user : User, group : Group) = {       
        create.member(user).group(group).state(MembershipState.Accepted).save
    } 
}
Was it helpful?

Solution

Try moving your MembershipState enum outside of the MembershipClass. I was getting the same error as you until I tried this. Not sure why, but the code compiled after I did that.

OTHER TIPS

_14 means a compiler-generated intermediate anonymous value. In other words, the compiler doesn't know how to express the type it's looking in a better way.

But if you look past that, you see the compiler is looking for a conversion from [...].Val to [...].Value. I would guess that changing

val Requested = new Val(1, "Requested")

to

val Requested = Value(1, "Requested")

would fix the error.

(I'm curious where you picked up the "new Val" style?)

What's strange is that Val actually extends Value. So if the outer type was known correctly (not inferred to the odd _14) Val vs. Value wouldn't be a problem. The issue here is that Lift from some reason defines the setters to take the now-deprecated view bound syntax. Perhaps this causes the compiler, rather than going in a straight line and trying to fit the input type into the expected type, instead to start from both ends, defining the starting type and the required type, and then start searching for an implicit view function that can reconcile the two.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top