aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Moss <maclover7@users.noreply.github.com>2016-08-22 21:46:57 -0400
committerGitHub <noreply@github.com>2016-08-22 21:46:57 -0400
commit479f3a955d8e09362519bbde304f7f06157f129a (patch)
tree705c9376d38c2269589ae771865bd10ead17b192
parentdebd774d632ae7e1e6c0a7d0306979159df39b63 (diff)
parente464d06696e402ae725cbb9d638d4aa1070c4d9b (diff)
downloadrails-479f3a955d8e09362519bbde304f7f06157f129a.tar.gz
rails-479f3a955d8e09362519bbde304f7f06157f129a.tar.bz2
rails-479f3a955d8e09362519bbde304f7f06157f129a.zip
Merge pull request #26231 from philipqnguyen/scoped-dependent-destroy
Doc on scoped has_many, dependent: :destroy
-rw-r--r--activerecord/lib/active_record/associations.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 659e512ce2..dc68b01386 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1296,6 +1296,12 @@ module ActiveRecord
# If using with the <tt>:through</tt> option, the association on the join model must be
# a #belongs_to, and the records which get deleted are the join records, rather than
# the associated records.
+ #
+ # If using <tt>dependent: :destroy</tt> on a scoped association, only the scoped objects are destroyed.
+ # For example, if a Post model defines
+ # <tt>has_many :comments, -> { where published: true }, dependent: :destroy</tt> and <tt>destroy</tt> is
+ # called on a post, only published comments are destroyed. This means that any unpublished comments in the
+ # database would still contain a foreign key pointing to the now deleted post.
# [:counter_cache]
# This option can be used to configure a custom named <tt>:counter_cache.</tt> You only need this option,
# when you customized the name of your <tt>:counter_cache</tt> on the #belongs_to association.