gpt4 book ai didi

joinTable(旧数据库)中多对多关系中复合键的Grails自定义名称

转载 作者:行者123 更新时间:2023-12-02 14:07:19 24 4
gpt4 key购买 nike

如果一个域类具有复合 id,grails/gorm 似乎会忽略多对多关系连接表上的列名,例如:

class Following implements Serializable {
...
static hasMany = [operationTypes:OperationType]
static belongsTo = OperationType
static mappedBy = [operationTypes:'followings']

static mapping = {
...
id composite: ['offer', 'user']
offer column: 'offer_oid'
user column: 'user_oid'
operationTypes joinTable: [name: 'operationtype_following', key: ['favorite_user_offer_oid', 'favorite_user_user_oid']]
}
}

和:

class OperationType implements Serializable {
...
static hasMany = [offers:Offer, advices:Advice, followings:Following]
static mappedBy = [followings:'operationTypes']

static mapping = {
....
followings joinTable: [name: 'operationtype_following', key: 'operationtype_oid']
}
}

结果: MappingException: 外键 (FK_lhri681gwbef5a9y6ylhoakpj:operationtype_following [favorite_user_offer_oid, favorite_user_user_oid,Following_offer_id,Following_user_id])) 必须与引用的主键 (favorite_user [user_oid,offer_oid]) 具有相同的列数

那么为什么它不真正忽略列名而是将生成的列名添加到指定的列名中呢?

使用 Grails 2.4.3。任何帮助表示赞赏

最佳答案

我能够在 m:m 关系中使用复合外键。这使用以下映射语法。 SITE和MACHINE_FK是连接表的属性。

static mapping = {
mstAttributeList {
column name: 'SITE'
column name: 'MACHINE_FK', sqlType: 'nvarchar2'
}
mstAttributeList joinTable: [name: 'MST_MACHINE_ATTRIBUTE', key: ['MACHINE_FK', 'SITE']]
}

static hasMany = [ mstAttributeList : com.gknsintermetals.mda.master.MstAttribute ]

关于joinTable(旧数据库)中多对多关系中复合键的Grails自定义名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25570843/

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