2009-12-08 63 views
14

我對使用靜態hasOne地圖和在域類中組合對象之間的差異有點困惑。兩者有什麼區別?即。Grails GORM組成還是hasOne?

class DegreeProgram { 

String degreeName 
Date programOfStudyApproval 
static hasOne = [committee:GraduateCommittee] 
} 

class DegreeProgram { 

String degreeName 
Date programOfStudyApproval 
GraduateCommittee committee 
} 

其中GraduateCommittee是另一個GORM域模型類。

回答

10

如果您希望將外鍵引用存儲在子表中而不是雙向一對一的父表中,則應使用hasOne關聯。

爲例見this page

+1

我脫脂之前,但它並沒有真正註冊。在什麼情況下,我想將父母的鑰匙存放在孩子身上,而反之亦然? – 2009-12-09 19:19:26

+0

@VisionarySoftwareSolutions我想這對於確保孩子不屬於另一個父母很有用,因爲它只能引用一個父母。 – 2014-04-24 11:31:54