aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorMarcel M. Cary <marcel@oak.homeunix.org>2018-11-13 15:29:43 -0800
committerMarcel M. Cary <marcel@oak.homeunix.org>2018-11-13 16:06:00 -0800
commit39806b6d98c1dbcbaac6748274e2cc3fbfba3495 (patch)
tree38c92dff90c53b009003aba16aefd82ec2c38b6b /guides
parent3dea7f0615144e891d4122697638db735fbea71d (diff)
downloadrails-39806b6d98c1dbcbaac6748274e2cc3fbfba3495.tar.gz
rails-39806b6d98c1dbcbaac6748274e2cc3fbfba3495.tar.bz2
rails-39806b6d98c1dbcbaac6748274e2cc3fbfba3495.zip
Describe how has_many's :dependent option affects #delete
I was puzzled about why `collection=` was destroying the removed records on an association with `dependent: :destroy`, even after consulting the documentation for that option. I had to dive into the Active Record source to understand what was going on: eventually `collection=` calls `collection.delete` on the ousted records, and it also uses the `:dependent` option to decide how to remove records. It would have helped me to have mention of this in the documentation for `:dependent`, not just under `collection.delete` (which I found much later). Briefly mention the broader impacts of `:dependent` in the Association Basics guide. [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/association_basics.md2
1 files changed, 2 insertions, 0 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index f75517c5ab..822dee08f0 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -1662,6 +1662,8 @@ Controls what happens to the associated objects when their owner is destroyed:
* `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there are any associated records
* `:restrict_with_error` causes an error to be added to the owner if there are any associated objects
+The `:destroy` and `:delete_all` options also affect the samantics of the `collection.delete` and `collection=` methods by causing them to destroy associated objects when they are removed from the collection.
+
##### `:foreign_key`
By convention, Rails assumes that the column used to hold the foreign key on the other model is the name of this model with the suffix `_id` added. The `:foreign_key` option lets you set the name of the foreign key directly: