如何: 在 Lift-Record-Squeryl 定制领域

我试着在 Lift/Record/Squeryl 中制作一个 EnumListField,类似于 LiftMapper中的 MappedEnumList。存储类型应该是 Long/BIGINT。我明白,如果我定义:

def classOfPersistentField = classOf[Long]

然后 Squeryl 就会知道它应该创建一个 BIGINT 列。我知道它使用 setFromAny()来设置值,传入 Long。我不明白的是:

它将如何读取字段的值?如果它使用 valueBox,它将得到一个 Seq[Enum#Value],并且它不知道如何将它转换成一个 Long。

如何告诉 Squeryl 将我的 Seq[Enum#Value]转换为 Long,或者定义一个返回 Long 的“ getter”,而这与“普通”getter (s)不冲突?

1248 次浏览

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.