2011-06-10 185 views
0

我遇到的问题与更新嵌套属性的引用文件不被坚持mongoid:更新嵌套属性

> u = User.first 
=> #<User... 
> u.changes 
=> {} 
> u.profile.changes 
=> {} 
> u.attributes = {:profile_attributes => {:weight => 8}} 
=> {:profile_attributes=>{:weight=>8}} 
> u.changes 
=> {} 
> u.profile.changes 
=> {"weight"=>[14.0, 8.0]} 
> u.update 
=> true 
> u.shipping_profile.changes 
=> {"weight"=>[14.0, 8.0]} 

更新/ update_attributes方法/保存所有不持久嵌套的变化。 我在用户模型中声明了attr_accessible :profile_attributes

嵌套属性在父文档已保存时需要保留什么?

回答

0

您的User课程中有以下内容吗?

accepts_nested_attributes_for :profile 

如果你错过了这条线,我敢肯定它会忽略所有尝试更新通过使用update_attributes父嵌套记录。

+0

是的,我也有这条线。忘了包括那个。 – brewster 2011-06-10 17:11:01