Support for hasOne mapping
GORM now supports hasOne mapping where the foreign key is stored in
the child instead of the parent association. For example:
class Person {
String name
static hasOne = [address: Address]
}
class Address {
String street
String postCode
In the above case a foreign key column called person_id will be
created in the address table rather than the default where an
address_id is created in the person table.
On 11月6日, 下午9时51分, Alex wang <idea.w...@gmail.com> wrote:
呵呵,看来我对一对一的关系理解有偏差啊。 thanks.
按照你刚才举例的User和UserInfo,我有一个问题,对于将外键放在User或者是放在UserInfo,对最终的业务使用方式上有没有什么不同 的地方? 都能够通过user访问到UserInfo?
业务上绝大部分都只使用User,有个别的地方需要先查询UserInfo的。我做了个联接查询,连User一块查了,这个地方应该算是有性能浪费。
还是合并的比较好,事比较少,性能也会提高,分开仅仅是看上去很美,大家觉得呢?
2009/11/12 Ali Yang <yang...@gmail.com>
用 的时候再查了,不算是性能浪费吧
2009/11/12 TigerF <tig...@gmail.com>
业务上绝大部分都只使用User,有个别的地方需要先查询 UserInfo的。我做了个联接查询,连User一块查了,这个地方应该算是有性能浪费。