2011-06-10 182 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