2016-10-10 79 views
0

我目前正在使用帶有MongoDB插件(org.grails.plugins:mongodb:6.0.0.RC2)的Grails 2.5.4,並且每當我嘗試更新任何域類的列表,它不起作用。gorm - Grails MongoDB在進行addTo/removeFrom時沒有更新列表

執行此代碼時,remove函數成功執行,save方法也執行。但數據庫中的記錄保持不變。

def updateMessage(){ 
    String id = '-1001066675850-7184293742' 
    Message message = Message.findById(id) 
    def entity = message.entities.get(0) 
    message.removeFromEntities(entity) 
    message.save(validate: true, failOnError: true, flush: true) 
    render message.entities 
} 

消息域類映射是這樣的:

class Message { 

User fromUser 
String text 
Chat chat 
Date sentDate 
List<MessageEntity> entities 
String sticker 
Point location 
String id 
boolean pinned = false 

static belongsTo = [entities: MessageEntity] 

static constraints = { 
    chat nullable: false 
    fromUser nullable: false 
    sentDate nullable: false 
} 

static hasMany = [entities: MessageEntity] 

static mapping = { 
    id generator: 'assigned' 
    location geoIndex: '2dsphere' 
} 

}

而且MessageEntity

class Message { 

User fromUser 
String text 
Chat chat 
Date sentDate 
List<MessageEntity> entities 
String sticker 
Point location 
String id 
boolean pinned = false 

static belongsTo = [entities: MessageEntity] 

static constraints = { 
    chat nullable: false 
    fromUser nullable: false 
    sentDate nullable: false 
} 

static hasMany = [entities: MessageEntity] 

static mapping = { 
    id generator: 'assigned' 
    location geoIndex: '2dsphere' 
} 

我試圖創建從從頭開始一個新的列表,將它添加到消息,它仍然不會更新。

有什麼我在文檔上丟失?

回答

0

顯然,更新列表在GORM for MongoDB 6.0.0.RC2或我(和朋友)環境中的某些特定設置上被破壞。

通過降級到版本3.0.1來解決它。