Grary
2010-Apr-13 20:10 UTC
how to remove dependents in has-many-belongs-to relationship before saving?
Hi, In my RESTful controller''s create method, how do I intercept and modify any dependents before saving? That is, I have a model that is the parent of nested associations gathered from a form. The first line of this model''s controller create method is: @parent = Parent.new(params[:parent]) What if I want to tour through the nested associations and possibly remove a few from the association before I proceed to save the parent in the create method? All the discussion of removing association models concerns the case when models have already been persisted to a database, not before they''ve been saved. I''ve been fiddling around with this, but can''t figure out a way to ''delete'' associations while they''re only in-memory. (By way of background, I create multiple ''rows'' representing each nested association in my parent model form. I allow the case that the user may submit the form with some of the nested association fields being blank. In that case, however, I''d like to sidestep any validations in those nested association models by removing the blank-y dependent model objects before the parent is saved.) Thanks for any comments, Grar -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.