MappedField 中的可选属性值
我是 Scala 和 Lift 的新手,在 PLT 方案方面的背景有点奇怪。我对此主题进行了快速搜索,发现了很多问题,但没有答案。我可能找错地方了。
我一直在学习如何使用 Mapper 创建数据库支持的对象的教程,但遇到了一个绊脚石:应该使用什么类型来存储可选属性值。
例如,一个简单的 ToDo 对象可能包含标题和可选的截止日期(例如 http://rememberthemilk.com)。前者可能是 MappedString,但后者不能是 MappedDateTime,因为字段上的类型约束要求返回 defaultValue Date
(而不是日期或 null/false/???)。
底层 NULL 是否由 MappedField 子类处理?或者是否有与 MappedInt
、MappedString
、MappedDateTime
等类似的可选等效项,允许数据库中的值为 NULL?或者我以错误的方式处理这个问题?
I'm new to Scala and Lift, coming from a slightly odd background in PLT Scheme. I've done a quick search on this topic and found lots of questions but no answers. I'm probably looking in the wrong place.
I've been working my way through tutorials on using Mapper to create database-backed objects, and I've hit a stumbling block: what types should be used to stored optional attribute values.
For example, a simple ToDo object might comprise a title and an optional deadline (e.g. http://rememberthemilk.com). The former would be a MappedString
, but the latter could not be a MappedDateTime
since the type constraints on the field require, say, defaultValue
to return a Date
(rather than a Date or null/false/???).
Is an underlying NULL handled by the MappedField subclasses? Or are there optional equivalents to things like MappedInt
, MappedString
, MappedDateTime
that allow the value to be NULL in the database? Or am I approaching this in the wrong way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解答提升问题的最佳地点是提升群组。他们不喜欢 Stack Overflow,但如果你访问他们的邮件列表,他们会非常乐于接受并且乐于助人。
The best place to have Lift questions answered is the Lift group. They aren't into Stack Overflow, but if you do go to their mailing list, they are very receptive and helpful.
大卫·波拉克回复道:
...这是正确的。
David Pollak replied with:
... which is spot on.