Why has_many update does not work on children?

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

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.

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