2011-11-07 68 views
0

如何在grails中建立兩個域類之間的關係。我已經從插件(spring安全插件)中獲得了一個域類,並且我想將USER域類從插件鏈接到Profile域類。什麼是最好的方式來做到這一點?grails中的域類

回答

6

請參閱GORM documentation以獲得良好的概述。對於一個一對一的關係,我假設一個配置文件將是,您可以簡單地執行以下操作:

class User { 
    Profile profile 
} 

class Profile { 
    // only needed if you need to refer to user from the Profile instance 
    static belongsTo = [user:User] 
}