From 032ab94332fd5496c5af627bc36445cea3ba476a Mon Sep 17 00:00:00 2001 From: "Daniel E. Garcia Shulman" Date: Wed, 2 Nov 2016 21:45:54 +0200 Subject: Fixes TypeError Exception when cache counter value equals nil (#26940) * Fixes TypeError when cache counter value equals nil * Test case for counter cache on unloaded has_many association --- activerecord/lib/active_record/associations/has_many_association.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index d1d0cc4c49..742cd25509 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -72,7 +72,7 @@ module ActiveRecord # the loaded flag is set to true as well. def count_records count = if reflection.has_cached_counter? - owner._read_attribute reflection.counter_cache_column + owner._read_attribute(reflection.counter_cache_column).to_i else scope.count end -- cgit v1.2.3