
[Patch] :dependent option for has_many, habtm associations
Reported by asceth | February 5th, 2008 @ 12:13 AM
Adds :dependent option to has_many, has_and_belongs_to_many relationships. (Secretly adds to has_one as well since its a has_many in disguise). Updates documentation to include new option and adds a new Error that can be thrown for the :protect value.
Possible values, what they do and for what association
has_many:
:destroy - associated objects have destroy! method called on them so callbacks are triggered.
:delete - associated objects are deleted from the database without their callbacks being triggered.
:protect - if the collection is not empty an AssociationProtectedError is thrown.
:nullify - associated objects foreign keys are set to NULL
default is :nullify
has_and_belongs_to_many:
:destroy - associated objects have their destroy! method called on them so callbacks are triggered. Beware of a cascading delete as any records remotely related to the original record being deleted will be destroyed.
:delete - associated objects are deleted from the database without their callbacks being triggered. This does NOT cascade deletes. All associated objects will have their relationships removed from other records before being deleted. The record calling destroy! originally will only delete records directly associated to it.
:protect - if the collection is not empty an AssociationProtectedError is thrown.
:nullify - the join table will have the relationship records removed which is effectively nullifying the foreign key.
default is :nullify
Request for comments.
Comments and changes to this ticket
-
asceth February 6th, 2008 @ 03:17 AM
Updated patch to allow the before_destroy to be called before the loaded associations are deactivated. This offers more flexibility with associations and being able to take care of them/access them before the object is destroyed.
-
Sam Smoot February 8th, 2008 @ 01:36 PM
- State changed from new to resolved
Resolved in... r724 I think.
-
Adam French February 9th, 2008 @ 08:22 PM
- State changed from resolved to open
1)
'DataMapper::Associations::HasManyAssociation should correctly handle dependent associations (:nullify)' FAILED
expected nil, got 0
./spec/associations/has_many_association_spec.rb:327:
this fails using the postgresql adapter though I think this is related to
http://wm.lighthouseapp.com/proj...
where nil values are being marshaled as 0 coming out of the database
-
Dan Kubb (dkubb) April 15th, 2008 @ 03:29 AM
- Milestone cleared.
-
Sam Smoot May 8th, 2008 @ 05:13 PM
- State changed from open to resolved
This is resolved in DO 0.9.0.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Tags
Referenced by
-
466 :dependent does not work I saw this ticket: #148. It is closed. So I should have b...
-
466 :dependent does not work Is the code of #148 still useable?