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.

rails 2.3.8 : accepts_nested_attributes_for and attributes= broken

#6615

It seems that combinaison of accepts_nested_attributes_for and attributes= is broken into rails 2.3.8.
The problem occurs whith following models :

class Book < ActiveRecord::Base
  has_many :authors
  accepts_nested_attributes_for authors
end

class Author < ActiveRecord::Base
  belongs_to :book
end

and a params hash like this :

params = {:name=>"a great book", "authors_attributes"=>{"1"=>{:id"=>"2", "_destroy"=>"", :name => "Boney M"}}}

Calling

book.attributes=params

do not set @loaded to true into authors AssociationProxy of object book. So the next call to

book.authors

will reload author objects from database.

This was not the case in rails 2.3.5, What is the normal behaviour ?

ps : I saw ticket 2646 and it seems to me to be a different problem.

Reported by ajoulie · March 24th, 2011 @ 08:21 AM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

No comments yet.