Hey all, I''m using nested model creation in my forms, but I''ve noticed that when I go to try and destroy a nested model, the backing DB row gets destroyed but the child object is never set back to nil as I expected it to be. This leaves me with an object that doesn''t have a backing DB row. The object is, however, frozen and I can call "destroyed?" on the object which returns true. Is this expected and defined behavior? I couldn''t find this referenced anywhere as it seems that the docs indicate the object would be set back to nil. I''m simply resetting the object to nil if it has been destroyed after I save the record, so this isn''t a problem, just not something I expected. Maybe the docs should be updated? Some background info: I''m using rails 2.3.5 running on jruby-1.3.1. This is a has_one relationship and :allow_destroy is set to true in the parent model. Documentation I was looking at: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html Thanks! tony -- 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.
Hi, Maybe this can help (taken from Rails Guides - http://guides.rubyonrails.org/association_basics.html#belongs-to-association-reference): 4.1.2.5 :dependent If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method. Best, Martin On 20 Sty, 06:35, Tony <tony.cassan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey all, > > I''m using nested model creation in my forms, but I''ve noticed that > when I go to try and destroy a nested model, the backing DB row gets > destroyed but the child object is never set back to nil as I expected > it to be. This leaves me with an object that doesn''t have a backing > DB row. The object is, however, frozen and I can call "destroyed?" on > the object which returns true. Is this expected and defined > behavior? I couldn''t find this referenced anywhere as it seems that > the docs indicate the object would be set back to nil. > > I''m simply resetting the object to nil if it has been destroyed after > I save the record, so this isn''t a problem, just not something I > expected. Maybe the docs should be updated? > > Some background info: I''m using rails 2.3.5 running on jruby-1.3.1. > This is a has_one relationship and :allow_destroy is set to true in > the parent model. > > Documentation I was looking at:http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/Clas... > > Thanks! > > tony-- 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.
Thanks for the response. I''m not actually deleting the parent object, just deleting a nested object (the child) from a has_one relationship. Everything is working, just simply behaving differently from the documentation. I just wanted to confirm that I am seeing the appropriate behavior. It seems the documentation may be out of date. tony On Jan 19, 11:50 pm, Marcin Seroczynski <sere...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Maybe this can help (taken from Rails Guides -http://guides.rubyonrails.org/association_basics.html#belongs-to-asso... > > 4.1.2.5 :dependent > > If you set the :dependent option to :destroy, then deleting this > object will call the destroy method on the associated object to delete > that object. If you set the :dependent option to :delete, then > deleting this object will delete the associated object without calling > its destroy method. > > Best, > Martin > > On 20 Sty, 06:35, Tony <tony.cassan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hey all, > > > I''m using nested model creation in my forms, but I''ve noticed that > > when I go to try and destroy a nested model, the backing DB row gets > > destroyed but the child object is never set back to nil as I expected > > it to be. This leaves me with an object that doesn''t have a backing > > DB row. The object is, however, frozen and I can call "destroyed?" on > > the object which returns true. Is this expected and defined > > behavior? I couldn''t find this referenced anywhere as it seems that > > the docs indicate the object would be set back to nil. > > > I''m simply resetting the object to nil if it has been destroyed after > > I save the record, so this isn''t a problem, just not something I > > expected. Maybe the docs should be updated? > > > Some background info: I''m using rails 2.3.5 running on jruby-1.3.1. > > This is a has_one relationship and :allow_destroy is set to true in > > the parent model. > > > Documentation I was looking at:http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/Clas... > > > Thanks! > > > tony-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.