92

I'm trying to make a EnumListField in Lift/Record/Squeryl, similar to MappedEnumList in LiftMapper. The storage type should be Long/BIGINT. I understand that if I define:

def classOfPersistentField = classOf[Long]

Then Squeryl will know it should create a BIGINT column. And I know it uses setFromAny() to set the value, passing in the Long. The one piece I don't get is:

How will it read the field's value? If it uses valueBox, it will get a Seq[Enum#Value], and it won't know how to turn that into a Long.

How do I tell Squeryl to convert my Seq[Enum#Value] to a Long, or define a "getter" that returns a Long, and that doesn't conflict with the "normal" getter(s)?

The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85

1 Answers1

1

you are implementing your validation logic incorrectly. The correct way to validate a Record field is to override

def validations: List[ValidationFunction]

where ValidationFunction is a type alias

type ValidationFunction = ValueType => List[FieldError]

and in your case ValueType == String.

The next issue is your Domain trait. Because your call to validate is inlined into the class definition, it will be called when your field is constructed.

Gucci
  • 921
  • 1
  • 7
  • 27
  • I haven't used Scala, and therefore Lift/Record/Squeryl, for over 5 years. I've forgoten all about it, and so I'm not qualified anymore to decide if your answer is correct and solves the problem. I'm not sure what the Stack-Overflow "process" should be in this case. I'll ask in "meta" ... – Sebastien Diot Mar 14 '18 at 10:04
  • "Meta" said "wait and see"; if your answer gets a bunch of +1, then it's "probably right", and I can accept it... – Sebastien Diot Mar 14 '18 at 17:25