HowTo:Lift-Record-Squeryl中的自定义字段

Seb*_*iot 92 scala record lift squeryl

我试图做一个EnumListField在电梯/录音/ Squeryl,类似MappedEnumListLiftMapper.存储类型应为Long/BIGINT.我明白,如果我定义:

def classOfPersistentField = classOf[Long]
Run Code Online (Sandbox Code Playgroud)

然后Squeryl会知道它应该创建一个BIGINT列.我知道它用于setFromAny()设置值,传入Long.我没有得到的一件是:

它将如何读取该领域的价值?如果它使用valueBox,它将得到一个Seq[Enum#Value],它将不知道如何将其变成一个龙.

我如何告诉Squeryl将我转换Seq[Enum#Value]为Long,或者定义一个返回Long的"getter",并且不与"普通"getter冲突?

Guc*_*cci 1

您错误地实施了验证逻辑。验证记录字段的正确方法是覆盖

def validations: List[ValidationFunction]
Run Code Online (Sandbox Code Playgroud)

其中 ValidationFunction 是类型别名

type ValidationFunction = ValueType => List[FieldError]
Run Code Online (Sandbox Code Playgroud)

在你的情况下 ValueType == String。

下一个问题是你的领域特质。因为您对 validate 的调用已内联到类定义中,所以在构造字段时将调用它。