aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-09-26 23:37:09 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-09-26 23:45:08 +0900
commita592e87a278cec10569d854dd5ece22179471bc0 (patch)
treee6806c20f83a43dac6126b360e91a554f6807424 /activerecord/lib/active_record
parent52e11e462f6114a4d12225c639c5f501f0ffec7a (diff)
downloadrails-a592e87a278cec10569d854dd5ece22179471bc0.tar.gz
rails-a592e87a278cec10569d854dd5ece22179471bc0.tar.bz2
rails-a592e87a278cec10569d854dd5ece22179471bc0.zip
Remove force parent loading when counter cache child is created/destroyed
`association.increment_counters` and `association.decrement_counters` works regardless of parent target is loaded or not. Related 52e11e462f6114a4d12225c639c5f501f0ffec7a.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb8
1 files changed, 2 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index aad30b40ea..27c1b7a311 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -163,9 +163,7 @@ module ActiveRecord
id = super
each_counter_cached_associations do |association|
- if send(association.reflection.name)
- association.increment_counters
- end
+ association.increment_counters
end
id
@@ -178,9 +176,7 @@ module ActiveRecord
each_counter_cached_associations do |association|
foreign_key = association.reflection.foreign_key.to_sym
unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key
- if send(association.reflection.name)
- association.decrement_counters
- end
+ association.decrement_counters
end
end
end