操作方法: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 冲突)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您错误地实施了验证逻辑。验证记录字段的正确方法是覆盖
ValidationFunction 是类型别名的情况
,在您的情况下 ValueType == String。
下一个问题是你的领域特质。因为您对 validate 的调用已内联到类定义中,所以在构造字段时将调用它。
you are implementing your validation logic incorrectly. The correct way to validate a Record field is to override
where ValidationFunction is a type alias
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.