Grails 跨同一个表的多对多关系
我正在使用 Grails,并且想要建立单向的多对多关系。
在我的应用程序中,员工可以为另一名员工“添加书签”,以便快速访问他们并留下笔记。员工不需要知道谁给他们添加了书签。
换句话说,我本质上希望拥有一个可以用于此目的的 employee.bookmarks
属性。
到目前为止,我已经找到了 有关 Grails ORM 的多对多关系的文档,但这似乎只跨两个不同表。
I'm using Grails and I want to have a unidirectional many-to-many relationship.
In my application, an Employee can "bookmark" another Employee in order to quickly access them to leave notes. Employees need not know who has bookmarked them.
In other words, I essentially want to have an employee.bookmarks
property that I can use for this.
Thus far, I've found the documentation on many-to-many relationships for Grails ORM, but this seems to be exclusively across two different tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来你只需要一个常规的单向一对多:
Sounds like you just need a regular unidirectional 1-many:
您可以使用瞬态属性和一个附加表“书签”来完成此任务:
该方法使用表“书签”来存储员工之间的关系,因此可以有2个人为同一员工添加书签。请注意,Bookmark 类必须实现 Serialized。
You can use transient properties and an additional table "Bookmark" to do this task:
This method uses table "Bookmark" to store the relations between employees, so it is possible to have 2 people bookmark the same employee. Note that class Bookmark must implements Serializable.