Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH]: Nested Attributes update associated record w/o passing id on one to one

#3418

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,

Reported by Nobuhiro IMAI · October 23rd, 2009 @ 02:12 PM

State: resolved
Milestone: none
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. Eloy Duran
    Eloy Duran
    • 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...

    December 30th, 2009 @ 07:53 PM

  2. Nobuhiro IMAI
    Nobuhiro IMAI

    It sounds good and works fine for me, thanks!

    December 31st, 2009 @ 02:15 AM

  3. Eloy Duran