【问题标题】:unable to push multiple embeds after mongoid upgrademongoid 升级后无法推送多个嵌入
【发布时间】:2019-04-19 13:49:02
【问题描述】:

我最近将 mongoid 更新到 6.x。在我的一个 rspec 测试中,我使用这个约定来持久化嵌入式文档:

parent.children.push(child1, child2, child3, etc...)

在这种情况下,父模型和子模型都有 after_update 回调。这工作正常,但在 mongoid 升级后,我现在得到:

NoMethodError (undefined method `call' for #<ActiveSupport::Callbacks::CallbackSequence:0x00007fcde9684c00>)

如果我将测试更改为单独推送,它可以正常工作,即:

parent.children.push(child1)
parent.children.push(child2)
etc...

我已经搜索了很多,但还没有找到与此相关的任何内容。我只是“做错了”吗?

【问题讨论】:

  • 试试parent.push(childrens: [child1, child2, child3])

标签: ruby-on-rails mongoid


【解决方案1】:

我按照建议尝试了parent.push(childrens: [...]),但产生了这个错误:

NoMethodError: undefined method `bson_type' for #<Child:0x00007fd7073ce520>
from /mongoid-6.1.1/lib/mongoid/attributes/dynamic.rb:137:in `method_missing'

【讨论】:

    【解决方案2】:

    看起来这可能是 Mongoid 版本的问题。我没有意识到它现在达到了 v.7。我更新到最新的 7.0.2,这个问题似乎已经解决了。

    【讨论】:

    • 升级到 v7.0.2 后是否遇到其他问题?我也计划升级我的项目。
    猜你喜欢
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多