> >> pfrom.children=[] >> >> would do it. >> >> > That's actually *exactly* what will do it. :) > > Running that will do a single UPDATE query to set all the involved > parent_id columns to NULL. So one way to implement the swap is: > > saved_children = pfrom.children.to_a > pfrom.children = [] > pto.children = saved_children > > This will depend on what you have set the :dependant option on the association to - it would do this if you have set the option to nullify (the default), but it would destroy the children if it was :destroy or :delete_all
Fred > NOTE: this won't work if there are children on pto already. For that, try > `pto.children = pto.children + saved_children`. > > --Matt Jones > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5c9e60da-12b7-40b4-a1ff-fe44830308fb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.