我有 2 个域类; A 和 B。
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'
}
}
关于mysql - Grails:如何将外键设为主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46005746/