Clarify has_many :dependent option docs [ci skip]

Clarifies the documentation here to mean all options are for when the
relation is destroyed; also now reflects the documentation on this same
option found in the has_one section.
This commit is contained in:
Chris Arcand 2016-03-11 11:22:34 -05:00
parent f8d9c05107
commit 5147ab121d
1 changed files with 6 additions and 8 deletions

View File

@ -932,15 +932,13 @@ side of the association.
Counter cache columns are added to the containing model's list of read-only attributes through `attr_readonly`.
##### `:dependent`
If you set the `:dependent` option to:
Controls what happens to associated objects when their owner is destroyed:
* `:destroy`, when the object is destroyed, `destroy` will be called on its
associated objects.
* `:delete_all`, when the object is destroyed, all its associated objects will be
deleted directly from the database without calling their `destroy` method.
* `:nullify`, causes the foreign key to be set to `NULL`. Callbacks are not executed.
* `:restrict_with_exception`, causes an exception to be raised if there is an associated record
* `:restrict_with_error`, causes an error to be added to the owner if there is an associated object
* `:destroy` causes the associated objects to also be destroyed.
* `:delete_all` causes the associated objects to be deleted directly from the database (callbacks are not executed).
* `:nullify` causes the foreign keys to be set to `NULL` (callbacks are not executed).
* `:restrict_with_exception` causes an exception to be raised if there are associated records.
* `:restrict_with_error` causes an error to be added to the owner if there are associated objects.
WARNING: You should not specify this option on a `belongs_to` association that is connected with a `has_many` association on the other class. Doing so can lead to orphaned records in your database.