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。任何帮助表示赞赏
答案 0 :(得分:1)
我能够在m:m关系中使用复合外键。这使用以下映射语法。 SITE和MACHINE_FK是连接表的属性。
request = (function () {
const pathAfter = {
start: ['homePage', 'GET', ({argObj}) => {console.log(`start`);}]
};
return {
go: (argObj) => {
if(!pathAfter[argObj.pathAfter]) return;
const path = pathAfter[argObj.pathAfter][0];
const method = pathAfter[argObj.pathAfter][1];
const url = data.domain + path + data.ext;
HTTP.call(method, url, (error, response) => {
if (error) {
console.log('error '+error);
} else {
pathAfter[path][2]({response: response}); // <---- calls relevant method
request.go({pathAfter: path});
}
});
return true; // if rms seccessful
}
};
}());
// function definition goes here...