This project is archived and is in readonly mode.

#3418 ✓resolved
Nobuhiro IMAI

[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

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>

People watching this ticket

Pages