The behaviour of deletion/destruction on associations can be confusing, and there is a lack of documentation. I have done some work recently to improve consistency across the different types of associations, and improve the documentation too.
So the current situation in master is that: * delete/destroy on an association removes the "link", and not necessarily the actual associated records. For has_many the "link" is the records itself, so there is no distinction. For has_many :through and has_and_belongs_to_many, only the join/through record is removed as this is the "link". * Doing a.association.delete(*records) will perform the deletion according to the :dependent option. Using the :dependent option basically causes a before_destroy callback to call a.association.delete_all. With has_many :through, if you want to remove the associated records also, then you should probably add the :dependent option to the source association in your join model. Jon On Sat, 2011-02-19 at 20:09 -0800, Solas wrote: > if a model A has_many :bee, :through => :c, :dependent => :destroy > ... > a.destroy properly cleans up all the bee's ... > > however. > If one does this: > > a.bees = [] > c records are destroyed... bees are untouched. > > This is misleading to me, as: while I can understand semantics that > just the "array" has been modified... > something like :dependent => :destroy should be invariant (the > dependents should be destroyed, under all cases where... the object is > a dependent) > > I am new to this list, so: how does one file a ticket? > > -Solas > -- http://jonathanleighton.com/
signature.asc
Description: This is a digitally signed message part
