mirror of https://github.com/rails/rails
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:
parent
f8d9c05107
commit
5147ab121d
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue