grails hasOne 但不属于

Mat*_*ake 1 grails hibernate grails-orm

我正在处理一个项目并且有一个Invoice域类,当前hasOne=[billingAddress:Address] 当我尝试启动我的服务器时,我收到以下错误:

hasOne property [Invoice.billingAddress] is not bidirectional. Specify the other side of the relationship!
Run Code Online (Sandbox Code Playgroud)

我不想分配关系的另一方...发票有一个账单地址但地址不属于发票。地址属于用户!!!

处理这种情况的正确方法是什么?

Ian*_*rts 5

听起来你只需要一个正常的关联而不是一个hasOne

class Invoice {
  // other properties

  Address billingAddress
}
Run Code Online (Sandbox Code Playgroud)

hasOne机制是一种更改关联的数据库表示的方法,传统的Address billingAddress您将billing_address_idinvoice表中得到一列,而hasOne关联则由address表中的外键表示 - 这种表示只允许一个Invoice用于each Address,这就是为什么关联必须是双向的。