Grails:如何使外键成为主键
问题描述:
我有2个域名classess; A和BGrails:如何使外键成为主键
class A {
Long a_id
static constraints = {
}
static mapping = {
id name:'a_id'
}
}
Class B {
A a
static constraints = {
}
static mapping = {
id name:'a', generator: 'assigned'
}
}
在域B中,我想使“A”作为主键,也可以作为外键(引用到A.a_id)
上面的代码不工作。请帮帮我。
答
您可以使主键始终与外键相同。并将外键指向主键。
Class B {
A a
static mapping = {
id generator:'foreign', params:[property:'a']
a insertable: false, updateable: false , column:'id'
}
}
我可能是错的,但你可以尝试添加你的域名B'belongsTo = [a:A]' – fsi