嵌入许多嵌套形式,mongoid

Gag*_*gan 5 document mongoid

我使用mongoid作为我的数据库.

我的模型是这样的

class Address
  include Mongoid::Document
  embedded_in :person, :inverse_of => :addresses
end

class Person
  include Mongoid::Document
  embeds_many :addresses
end
Run Code Online (Sandbox Code Playgroud)

我在设置动态嵌套人员表单时遇到问题,用户可以在表单中添加多个地址并立即保存所有地址.更新人员嵌套表单时我的哈希是这样的

"person"=>{"name"=>"John", 
"addresses_attributes"=>{"0"=>{"address1"=>"calgary","address2"=>"New York", "id"=>"4cef79f67adf3509280001be"}, 
                         "1"=>{"address1"=>"bhah", "address2"=>"blah", "id"=>"4cef74rdeadf3509280001bf"}}, 
"policy_id"=>"4cef5feb7adf35092800013a", 
"start_date"=>"2010-11-10", "end_date"=>""}
Run Code Online (Sandbox Code Playgroud)

但是根据收到的哈希值,地址没有得到更新.

知道为什么会这样吗?

谢谢

小智 0

尝试将 Accepted_nested_attributes_for 添加到您的 Person 模型中