Wes Gamble
2007-Jan-19 23:07 UTC
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Jan-20 11:43 UTC
Re: Does AR::Base#save update the entire object tree on update?
Wes Gamble 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2007-Jan-20 23:08 UTC
Re: Does AR::Base#save update the entire object tree on upda
Mark Reginald James 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---