#148 ✓resolved
asceth

[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

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.

New-ticket Create new ticket

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

Referenced by

Pages