On 20 Jul 2006, at 9:55 am, Rimantas Liubertas wrote:

On 7 Jun 2006, at 6:36 am, Chris Mear wrote:

A couple of weeks ago I noticed a bug with :dependent => :nullify on a has_many or has_one. When you delete the parent, the children's foreign keys are nullified, as expected. But when you do parent.child.delete or parent.children.clear, ActiveRecord actually deletes the child records, rather than just nullifying them

It just do what you ask it to. :dependent specifies what to do with
children when _parent_ is deleted.

With call to parent.child.delete or parent.children.clear you specifically ask
to delete children, and AR just does that.

Sorry, my slip. In my original post, I didn't mean to say 'parent.child.delete'. Obviously, that should delete the child record. I meant to say 'parent.child = nil'. Apologies for confusing the issue.

To restate my point:

If you *haven't* specified :dependent => :something, then when you call parent.children.clear or parent.child = nil, the children are nullified, not deleted. This is the default behaviour.

But when you specify :dependent => :nullify, then, all of a sudden, calls to parent.children.clear or parent.child = nil result in the children being deleted, not nullified. In my eyes, that's unexpected behaviour. I haven't asked for my children to be deleted, and yet they are being deleted.

Chris

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to