aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-27 01:40:00 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-05-27 02:33:47 +0900
commit6349ad300f2cace625b1c733410c4a39c91028ec (patch)
tree1146dfc488052e55fad9092da111a5e6070e3036 /activerecord/lib/active_record/associations/builder
parentcbab69c2789ff49bd9e3580eba0ac273190c9dc7 (diff)
downloadrails-6349ad300f2cace625b1c733410c4a39c91028ec.tar.gz
rails-6349ad300f2cace625b1c733410c4a39c91028ec.tar.bz2
rails-6349ad300f2cace625b1c733410c4a39c91028ec.zip
Fix `belongs_to_counter_cache_after_update` to respect polymorphic type change
Diffstat (limited to 'activerecord/lib/active_record/associations/builder')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 1dd6e5bed8..9e012285e5 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -36,7 +36,7 @@ module ActiveRecord::Associations::Builder # :nodoc:
if (@_after_replace_counter_called ||= false)
@_after_replace_counter_called = false
- elsif saved_change_to_attribute?(foreign_key) && !new_record?
+ elsif association(reflection.name).target_changed?
if reflection.polymorphic?
model = attribute_in_database(reflection.foreign_type).try(:constantize)
model_was = attribute_before_last_save(reflection.foreign_type).try(:constantize)