1

我在将数据绑定与继承模型一起使用时遇到问题。那是我的代码:

class Member {
   int age

   static belongsTo = [Family]
   static constraints = {}
}

class Parent extends Member {
   String name
   static constraints = {}
}

class Family {
    String name
    List members
    static hasMany = [members: Member]
    static constraints = {}
}


def test(){
    def bindingMap = [name: 'toto', members:[[age: 18, name: '1'],[age: 18]]]
    def family = new Family()
    family.properties = bindingMap
    family.save(flush: true)
    def get = Family.get(family.id)
    // here family only contains Member and no Parent, as expected...
}

如您所见,使用此代码,我无法使用数据绑定创建父级。有人有想法吗?

谢谢

4

0 回答 0