views:

63

answers:

0

I am finding (noodling around in script/console) that if I add a new item to the associated collection, I don't have to call foo.reload to see the resulting change:

foo.bars
=> []
foo.bars_attributes = [{ :person_id => '288', :task_id => '1237' }]
=> [{ :person_id=>"288", :task_id=>"1237" }]
foo.save
=> true
foo.bars
=> [#<Bar id: 6, person_id: 288, task_id => 1237>]

Terrific. But when I remove an item from the collection, I do have to call foo.reload before the change (visible in DB after call to save) is reflected in my collection:

foo.bars_attributes = [{ :id => '6', :_delete => '1' }]
= [{ :_delete=>"1", :id=>"6" }]
foo.save
=> true
foo.bars
=> [#<Bar id: 6, person_id: 288, task_id => 1237>]
foo.reload
foo.bars
=> []

Is this normal, or am I doing something slightly wrong in the association update?