2013-03-19 94 views
0

这里是域类GORM - MongoDB中不会对父类保存项目设置

class Settings { 
    static constraints = { 
     uid(nullable: false, unique: true) 
     data() 
    } 
    static hasMany = [items: Item] 
    Map data 
} 

class Item{ 

    static constraints = { 
     name() 
     email() 
     approved() 
    } 

    static mapping = { 
     email index: true, indexAttributes: [unique: true] 
    } 

    String name 
    String email 
    Boolean approved = false; 
} 

基本上有有许多项目的许多设置对象(见插图下面): Data Structure

现在我找到并更新像这样的项目:

... 
     def item = (Item)Item.findByEmail(email); 
     if (!item.approved) { 
      item.approved = true; 
      item.save(flush: true); 
     } 
... 

未保存我缺少什么吗?

回答

0

默认情况下,MongoDB不会使用空字段。一旦我添加了一个值,一切正常:

... 
    def item = (Item)Item.findByEmail(email); 
    if (!item.approved) { 
     item.approved = true; 
     item.name = "MyName"; 
     item.save(flush: true); 
    } 
...