gpt4 book ai didi

grails - 如何在一个域类中混合 'Reference' 和 'No Reference' 属于关系?

转载 作者:行者123 更新时间:2023-12-02 18:18:50 28 4
gpt4 key购买 nike

GrailsbelongsTo允许一个域类与另一个域类建立级联关系。使用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 调用?

有关如何在单个域类中混合无引用关系链接与引用属性的任何信息都会有所帮助。

链接:

最佳答案

class Engine {
User user
static belongsTo = [Car, User]
}

也就是说,我总是使用映射(引用)语法而不是列表(无引用)语法,因为我喜欢我的语法是双向的。

关于grails - 如何在一个域类中混合 'Reference' 和 'No Reference' 属于关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5914951/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com