如何混合映射的“参考”并列出“无参考”;一个域类中有许多关系?
在 Grails 中,hasMany
允许一个域类与另一个域类建立级联has Many关系。使用 hasMany
时有两种主要的关系样式:映射属性引用和列出无属性引用。
带有属性引用的 hasMany
:
class Car {
static hasMany = [parts:Part, wheels:Wheel]
}
没有属性引用的 hasMany
关系:
class Car {
static hasMany = [Part, Wheel]
}
问题来了,如何混合上述两种样式?
假设我想要直接引用轮子,但我不想要零件的域属性引用。
我该如何在域类中编写此代码?
In Grails hasMany
allows one domain class to establish a cascading has many relationship with another domain class. There are two main styles of relationships when using hasMany
: a mapped property Reference and listed no property reference.
hasMany
with property references:
class Car {
static hasMany = [parts:Part, wheels:Wheel]
}
hasMany
relationships without property references:
class Car {
static hasMany = [Part, Wheel]
}
Here's the problem, how do I mix the two above styles?
Say I want to have a direct reference to the Wheels, but I don't want a domain property reference for the Parts.
How would I write the code for this in the Domain Class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但问题是,即使您没有定义它,您最终也会在您的域中得到一个
Setwheels
。如果您查看最新的 Grails 网站上的文档,地图版本是更常见的方法。Here's the rub though, even if you don't define it, you will end up with a
Set wheels
in your domain. And if you look at the latest documentation on the Grails web site, the map version is the more common approach.