Daniel Rikowski
Daniel Rikowski

Reputation: 72504

How can I update a record if it is added to an association?

I have this data structure:

Root
  Child
    Child
  Child
    Child
      Child
  Child

My models are set up like this:

For some tasks every child has a back reference to the Root record.

How can I make sure, every time a new a child gets inserted, the root reference gets updated to?

Currently only the immediate children are set correctly:

I suspect I can only do this manually...

Upvotes: 0

Views: 68

Answers (1)

jdl
jdl

Reputation: 17790

Manually, yes. But it's still a clear and clean way of expressing what you're trying to do.

c.children.new(:root_id => c.root_id)

Upvotes: 1

Related Questions