I have two models and they have has_many and belongs_to relationships. When I have updated one of the childs of the parent using “ parent.childs[0].name = ‘johny walker’ “ and called “ parent.save! “; it does not saves the child rows which I have updated; except only the parent.created_at field in the database is being updated. Should I loop over the child rows and call their save method instead of the parent to make the job byself ? Regards -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
The reason it doesn''t automatically save the children is because a save operation is very expensive, and Rails doesn''t keep track of which children you have updated (which in and of itself would be very ugly and perform poorly). The solution is to explicitly save any children you have modified. I would certainly avoid looping over and saving the children unless you are modifying all the children. Otherwise you should only be saving the ones you updated. Inanc Gumus wrote:> I have two models and they have has_many and belongs_to relationships. > When I have updated one of the childs of the parent using " > parent.childs[0].name = ''johny walker'' " and called " parent.save! "; it > does not saves the child rows which I have updated; except only the > parent.created_at field in the database is being updated. > > Should I loop over the child rows and call their save method instead of > the parent to make the job byself ? > > Regards > > -- > 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 -~----------~----~----~----~------~----~------~--~---
dasil003 wrote:> The reason it doesn''t automatically save the children is because a save > operation is very expensive, and Rails doesn''t keep track of which > children you have updated (which in and of itself would be very ugly > and perform poorly). The solution is to explicitly save any children > you have modified. > > I would certainly avoid looping over and saving the children unless you > are modifying all the children. Otherwise you should only be saving > the ones you updated.I also have read rail trac archives a bit last night and seen many discussions going on about this topic. There are folks who have tried and still trying to track the modification status of an attribute of a model, so that they could only update those individual attributes which has updated. They were discussing there are many pitfals and balances to get this idea into real. Thanks dasil -- 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 -~----------~----~----~----~------~----~------~--~---