aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorLisa Ugray <lisa.ugray@shopify.com>2017-07-19 14:56:35 -0400
committerLisa Ugray <lisa.ugray@shopify.com>2017-07-21 13:58:10 -0400
commitcb8d8909910e3c6d3b62574e8ce41a024323a00d (patch)
tree0e492534e5001beab6f7d2f717352388438d2e59 /activerecord/lib
parent1f7f872ac6c8b57af6e0117bde5f6c38d0bae923 (diff)
downloadrails-cb8d8909910e3c6d3b62574e8ce41a024323a00d.tar.gz
rails-cb8d8909910e3c6d3b62574e8ce41a024323a00d.tar.bz2
rails-cb8d8909910e3c6d3b62574e8ce41a024323a00d.zip
Match destroyed_by_association for has_one to has_many
When a has_many association is destroyed by `dependent: destroy`, destroyed_by_association is set to the reflection, and this can be checked in callbacks. This matches that behaviour for has_one associations.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index 8458253ff8..d2e5efed74 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -56,6 +56,7 @@ module ActiveRecord
when :delete
target.delete
when :destroy
+ target.destroyed_by_association = reflection
target.destroy
when :nullify
target.update_columns(reflection.foreign_key => nil) if target.persisted?
@@ -78,6 +79,7 @@ module ActiveRecord
when :delete
target.delete
when :destroy
+ target.destroyed_by_association = reflection
target.destroy
else
nullify_owner_attributes(target)