I've got a form that collects data for a parent and a number of child records. I'm trying to update all the records and
then do one @parent.save to transactionally save the whole
bunch, but am having trouble.

My form gives me params[:parent] and params[:children]
The latter is a hash of hashes, each one containing the
info to find and fill out or modify one child.
The simplified version of the handler code is:

---------------------------------------
 @parent = Parent.find(foo)

 @parent.attributes = params[:parent]

 params[:children].each_value do |child_hash|
   child = Child.find(child_hash[:id])
child.attributes = child_hash ????????
 end

 if @parent.save
   yay
 end
---------------------------------------

The problem is that I need to know what goes at "????"
in order to associate the child objects with the parent such
that when I do the save, the children are updated as well.

I can't use:

 @parent.children << child

because that immediately saves the child.  I want to delay
the save until the transaction.  On the other hand, if I put
nothing at all there, then the children's updates are not saved.

Thanks in advance.

                -glenn

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to