aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_association.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-02-03 13:25:15 -0700
committerSean Griffin <sean@thoughtbot.com>2015-02-03 13:28:07 -0700
commit23bb8d77c6c5ace445659d56cf5df2adcf6c8dc3 (patch)
treeb5792b0fd965091f07e832f19bf1b3a4122aa7e0 /activerecord/lib/active_record/associations/has_many_association.rb
parent4a62724c59d387991055dbcb86d725e26a986fda (diff)
downloadrails-23bb8d77c6c5ace445659d56cf5df2adcf6c8dc3.tar.gz
rails-23bb8d77c6c5ace445659d56cf5df2adcf6c8dc3.tar.bz2
rails-23bb8d77c6c5ace445659d56cf5df2adcf6c8dc3.zip
Correct errors in counter cache updating
The cache name should be converted to a string when given, not compared as a symbol. This edge case is already adequately covered by our tests, but was masked by another issue where we were incorrectly updating the counter cache twice. When paired with a bug where we didn't update the counter cache because we couldn't find a match with the name, this made it look like everything was working fine. Fixes #10865.
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index b574185561..ca27c9fdde 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -85,7 +85,11 @@ module ActiveRecord
end
def cached_counter_attribute_name(reflection = reflection())
- options[:counter_cache] || "#{reflection.name}_count"
+ if reflection.options[:counter_cache]
+ reflection.options[:counter_cache].to_s
+ else
+ "#{reflection.name}_count"
+ end
end
def update_counter(difference, reflection = reflection())