Parent.children not updated (has_many)

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs