【问题标题】:gorm - Grails MongoDB not updating a list when doing addTo/removeFromgorm - Grails MongoDB 在执行 addTo/removeFrom 时不更新列表
【发布时间】:2016-10-10 23:28:34
【问题描述】:

我目前正在使用带有 MongoDB 插件 (org.grails.plugins:mongodb:6.0.0.RC2) 的 Grails 2.5.4,每当我尝试更新任何域类的列表时,它都不起作用。

当这段代码执行时,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'
    }
}

我尝试从头开始创建一个新列表,将其添加到消息中,但它仍然不会更新。

我在文档中遗漏了什么吗?

【问题讨论】:

    标签: mongodb grails plugins groovy grails-orm


    【解决方案1】:

    显然,在 GORM for MongoDB 6.0.0.RC2 或我(和朋友)环境中的某些特定设置上更新列表被破坏了。

    通过降级到版本 3.0.1 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-06
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      相关资源
      最近更新 更多