Forum: Ruby on Rails parent.children not updated (has_many)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Christian Schlack (Guest)
on 2006-04-15 13:45
(Received via mailing list)
Hi guys!

class Parent < ActiveRecord::Base
   has_many :children

class Child < ActiveRecord::Base
   belongs_to :parent

I do:

parent = Parent.find(1, :include => :children)
parent.children.find(3).update_attribute('name', 'Tom') (or
parent.children.find(3).name = 'Tom')

   => 'old value'

The database is updated correctly, SELECT name FROM children WHERE id=3
AND parent_id=1
   => 'Tom'

Only the array parent.children doesn't seem to get updated. I cannot
force reloading (parent.cildren(true).find(3).name would do the trick)
because I would possibly lose unsaved children.

How can I update the parent.children array?

- Christian
This topic is locked and can not be replied to.