Does AR::Base#save update the entire object tree on update?

On update (new_record? == false), if I call save on an AR::Base
descendant, is it guaranteed that the entire object graph is traversed
and each of the children is saved?

What I’m seeing is give an arbitrarily complex object graph of children
which belong to an object, when I save the object, the only objects
which get saved automatically are the children which are specified using
has_one, not any of the children specified using has_many.

Thanks,
Wes

Wes G. wrote:

On update (new_record? == false), if I call save on an AR::Base
descendant, is it guaranteed that the entire object graph is traversed
and each of the children is saved?

What I’m seeing is give an arbitrarily complex object graph of children
which belong to an object, when I save the object, the only objects
which get saved automatically are the children which are specified using
has_one, not any of the children specified using has_many.

New has_many children will be automatically saved (created).
This will continue down the association levels as long as
there’s an unbroken line of un-saved children.

Existing children are not updated.


We develop, watch us RoR, in numbers too big to ignore.

Mark Reginald J. wrote:

New has_many children will be automatically saved (created).
This will continue down the association levels as long as
there’s an unbroken line of un-saved children.

Existing children are not updated.

Mark,

This is helpful. I also found this post
(http://www.ruby-forum.com/topic/74822) from the core list which implies
that the automatic saving of has_one elements occurs as I’ve seen.

Upon further reflection, I see why one might not want automatic saving
of children. But in general, it seems like all the children should be
saved or none of them should be saved.

Anyone have any idea if the auto-saving of has_one associations will be
disabled in the future?

In the meantime, I will never assume that an object update will save
it’s children and handle it myself, in case this auto-saving behavior
for has_one goes away.

Thanks,
Wes