This project is archived and is in readonly mode.

#2415 ✓wontfix
vlad (at breyter)

accepts_nested_attributes_for does't work when nested_attributes hash has an :id entry

Reported by vlad (at breyter) | April 4th, 2009 @ 07:12 AM | in 3.0.2

When a parent accepts_nested_attributes_for :chilld and you call parent.update_attributes(hash) if the hash has an :id entry in the child_attributes subhash then the update_attributes call with return true without updating the associated object, this happens regardless of if the rest of the data in the subhash is valid or not, here is an example.

order = Order.first
=> #<Order id: 1, client_id: 1, amount: 123, created_at: "2009-04-03 23:09:03", updated_at: "2009-04-03 23:09:03">
attrs = {:client_attributes => {:state => "ASDASDADAD", :id => 12931204}}
=> {:client_attributes=>{:state=>"ASDASDADAD", :id=>12931204}}
order.client
=> #<Client id: 1, name: "blad", state: "NY", created_at: "2009-04-03 23:07:50", updated_at: "2009-04-03 23:07:50">
order.update_attributes(attrs)
=> true
order.client
=> #<Client id: 1, name: "blad", state: "NY", created_at: "2009-04-03 23:07:50", updated_at: "2009-04-03 23:07:50">
attrs = {:client_attributes => {:state => "ASDASDADAD"}}
=> {:client_attributes=>{:state=>"ASDASDADAD"}}
order.update_attributes(attrs)
=> false
order.client
=> #<Client id: nil, name: nil, state: "ASDASDADAD", created_at: nil, updated_at: nil>
order.errors.full_messages
=> ["Client state is not included in the list"]

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>

Referenced by

Pages