【问题标题】:can't modify frozen Hash in mongoid has_one dependent destroy无法修改 mongoid has_one 依赖破坏中的冻结哈希
【发布时间】:2013-08-28 19:35:26
【问题描述】:

当我将 mongoid 与 Rails 一起使用时,我将我的模型与 has_one 关系相关联并使用 像这样依赖销毁

 class MyModel 
   has_one :foo , :dependent => :destroy
 end
 class Foo
   belongs_to :mymodel
 end


 my_model.foo = Foo.new

然后它会导致以下错误

RuntimeError (can't modify frozen Hash):

但是如果我删除依赖的 destroy ,那么没有错误......我不确定为什么会这样

谁能帮帮我...提前谢谢

【问题讨论】:

    标签: ruby-on-rails-3.2 mongoid3


    【解决方案1】:

    【讨论】:

    • gem 'mongoid', " >= 3.1.4"
    • 我尝试了上面的链接,但没有用,感谢您的回复
    • self.foo = new_foo - 当我在 self 类上应用 :dependent => :destroy 时,此语句向我提出错误,但如果我删除依赖销毁,则它不会引发错误.. 我不确定为什么 ?有什么想法请...
    猜你喜欢
    • 2013-06-24
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    相关资源
    最近更新 更多