This project is archived and is in readonly mode.
[PATCH]: Nested Attributes update associated record w/o passing id on one to one
Reported by Nobuhiro IMAI | October 23rd, 2009 @ 02:12 PM
In #2777, Dmitry Polushkin said that passing id on
one to one relation is not smart.
I wrote patches to solve it. Excerpt from the RDoc:
class Member < ActiveRecord::Base
has_one :avatar
accepts_nested_attributes_for :avatar, :use_existing_record => true
end
member.avatar.id #=> 2
member.avatar.icon #=> 'sad'
params = { :member => { :name => 'Jack', :avatar_attributes => { :icon => 'smiling' } } }
member.update_attributes(params[:member])
member.avatar.icon #=> 'smiling'
Thanks,
Comments and changes to this ticket
-
Eloy Duran December 30th, 2009 @ 07:53 PM
- State changed from new to resolved
- Assigned user set to Eloy Duran
This has since already been fixed with the :update_only option. Thanks for the effort though!
http://github.com/rails/rails/commit/7074c5a6294a0f53839accd53a4314...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>