Google App Engine for Java 中的多对多关系(带有属性)
我从官方文档 对于无主关系,应用程序必须在关系的任一侧使用 Key 对象集。这是完全有道理的。
不过,经过多年的 RDBM 风格编程,我对如何对这种关系本身的属性进行建模感到非常困惑。例如,如果我的多对多关系中有实体 Category 和 Entry,并且希望保留 dateAdded
属性,或者某些属性仅当关系双方都已知时才相关的其他数据。
我想可以创建第三个类: CategoryEntry 来链接这两个类,但这看起来像是一个拼凑。
模拟这种情况的建议方法是什么?
I understand from the official documentation on unowned relationships that the app must use sets of Key objects on either side of the relationship. This makes perfect sense.
Coming from many years of RDBM-style programming, though, I'm pretty confused about how I can model properties of that relationship itself. For example, if I have entities Category and Entry in my many-to-many relationship and would like to persist a dateAdded
property, or some other data that are only relevant when both sides of the relationship are known.
I suppose it would be possible to create a third class: CategoryEntry that links the two, but this seems like a kludge.
What is the proposed way to model this kind of situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所描述的“关系表”是与属性建立关系的标准解决方案(无论是在 RDBMS 领域还是在 App Engine 数据存储区中)。这不是一个拼凑,因为当关系具有除其存在之外的属性时,它需要某个地方来表示它。
A 'relation table' such as you describe, is the standard solution - both in the RDBMS world and in the App Engine datastore - to having a relation with properties. It's not a kludge, because when the relation has attributes other than its existence, it requires somewhere to represent that.