如何将“参考”与“参考”混合在一起?和“无参考”属于一个域类中的关系?
在 Grails 中 belongsTo< /code>
允许一个域类与另一个域类建立级联关系。使用
belongsTo
时有两种类型的关系:引用和无引用。 Reference 在拥有的对象上创建属性,而 No Reference 仅建立不可见的 GORM 关系。
示例父域类:
class Car {
Engine engine
}
belongsTo
不带引用属性:
class Engine {
static belongsTo = Car
}
belongsTo
带有引用属性: >
class Engine {
static belongsTo = [car:Car]
}
不是很难,但是当我们开始使用多个belongsTo引用时,我的麻烦就开始了:
带有多个反向引用的belongsTo
:
class Engine {
static belongsTo = [car:Car, user:User]
}
多个belongsTo 没有财产的关系引用
:
class Engine {
static belongsTo = [Car, User]
}
问题是,如何混合上述两种样式?
假设我想要User
的属性引用,而不是Car的属性引用
,我该如何编写该 belongsTo
调用?
有关如何在单个域类中混合无引用关系链接与引用属性的任何信息都会有所帮助。
链接:
In Grails belongsTo
allows one domain class to establish a cascading relationship with another domain class. There are two styles of relationships when using belongsTo
: Reference and No Reference. Reference creates a property on the owned object while No Reference merely establishes an invisible GORM relationship.
Example parent domain-class:
class Car {
Engine engine
}
belongsTo
without Reference property:
class Engine {
static belongsTo = Car
}
belongsTo
with Reference property:
class Engine {
static belongsTo = [car:Car]
}
Not to hard right, however the trouble for me starts when we start using multiple belongsTo references:
belongsTo
with multiple back references:
class Engine {
static belongsTo = [car:Car, user:User]
}
multiple belongsTo
relationships without property references:
class Engine {
static belongsTo = [Car, User]
}
Here's the problem, how do I mix the two above styles?
Say I want a property reference for the User
but not for the Car
, how would I write that belongsTo
call?
Any information on how to mix No Reference relationship links with Reference property in a single domain class would help.
Links:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也就是说,我总是使用映射(引用)语法而不是列表(无引用)语法,因为我喜欢我的语法是双向的。
That said, I always use the map (reference) syntax over the list (no reference) syntax because I like mine to be bi-directional.