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

**URL:** <https://www.ruby-forum.com/t/does-ar-base-save-update-the-entire-object-tree-on-update/82723>\
**Category:** Rails\
**Created:** [January 20, 2007, 12:07am UTC](https://www.ruby-forum.com/t/does-ar-base-save-update-the-entire-object-tree-on-update/82723 "2007-01-20T00:07:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 20, 2007, 12:07am UTC](https://www.ruby-forum.com/t/does-ar-base-save-update-the-entire-object-tree-on-update/82723/1 "2007-01-20T00:07:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 20, 2007, 12:44pm UTC](https://www.ruby-forum.com/t/does-ar-base-save-update-the-entire-object-tree-on-update/82723/2 "2007-01-20T12:44:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 21, 2007, 12:08am UTC](https://www.ruby-forum.com/t/does-ar-base-save-update-the-entire-object-tree-on-update/82723/3 "2007-01-21T00:08:15Z")

</div>

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](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
