与 lift Mapper 的一对一关系
如何与 Mapper 实现一对一关系? 来自电梯维基:
如果您想要建立一对一关系的模型,只需使用一对多关系即可。唯一潜在的麻烦是您将拥有一个 List[B] 而不是 Box[B]。
难道就没有更惯用的方法吗?
How do I implement a One-to-One relationship with Mapper?
From Lift wiki:
If you’re looking to model a one-to-one relationship, just use a one-to-many relationship. The only potential hassle is that you’ll have a List[B] instead of a Box[B].
Isn't there a more idiomatic way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会通过降低一对多关系的可见性并创建一个 getter/setter 来实现它:
理想吗?不。但是比让客户端代码处理 List[Comment] 而不是 Option[Comment] 更惯用吗?我想是的。
沿着同样的思路,您还可以创建自己的类来扩展 MappedOneToMany。这段代码未经测试,但我相信它的精神:
I might approach it by reducing the visibility of the one-to-many relationship and create a getter/setter as such:
Ideal? No. But more idiomatic than having client code deal with the List[Comment] instead of Option[Comment]? I think so.
Along this same line, you could also create your own class which extends MappedOneToMany. This code is untested, but I believe in the spirit of it: