Grails 2.3.7数据库表不包含外键

时间:2016-03-18 03:14:42

标签: grails

我有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,请参见截图

enter image description here

enter image description here

当我将hasOne更改为hasMany时,我得到了预期的行为。

0 个答案:

没有答案
相关问题