我有2个域类User和Company
class User {
String name
String surname
static belongsTo = [ company : Company ]
static constraints = {
company nullable: true
}
}
和
class Company {
String name
User createdBy
static hasOne = [ user : User ]
static constraints = {
}
}
注意静态belongsTo = [company:Company]和static hasOne = [user:User]
但是当我查看我的数据库时,表User和Company都没有任何外键,并且只有两个表,所以没有COMPANY_USER或USER_COMPANY,请参见截图
当我将hasOne更改为hasMany时,我得到了预期的行为。