aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAdam Cooper <adam.cooper@gmail.com>2008-12-31 01:43:13 -0800
committerPratik Naik <pratiknaik@gmail.com>2009-03-06 22:05:18 +0000
commit3ca5a0f9fd7b7921bca970859da8637011b22dd1 (patch)
tree43a05f30708106cb98cab1e51dda07c8acd3352b /activerecord/lib
parent984bc7a614852944808739fae09a654b6e62872e (diff)
downloadrails-3ca5a0f9fd7b7921bca970859da8637011b22dd1.tar.gz
rails-3ca5a0f9fd7b7921bca970859da8637011b22dd1.tar.bz2
rails-3ca5a0f9fd7b7921bca970859da8637011b22dd1.zip
Ensure belongs_to association with a counter cache in name spaced model works [#1678 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb4
-rw-r--r--activerecord/lib/active_record/reflection.rb2
2 files changed, 2 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 80b3e23026..65a1319c7e 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1003,9 +1003,7 @@ module ActiveRecord
# Create the callbacks to update counter cache
if options[:counter_cache]
- cache_column = options[:counter_cache] == true ?
- "#{self.to_s.demodulize.underscore.pluralize}_count" :
- options[:counter_cache]
+ cache_column = reflection.counter_cache_column
method_name = "belongs_to_counter_cache_after_create_for_#{reflection.name}".to_sym
define_method(method_name) do
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index e69bfb1355..2d4c1d5507 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -197,7 +197,7 @@ module ActiveRecord
def counter_cache_column
if options[:counter_cache] == true
- "#{active_record.name.underscore.pluralize}_count"
+ "#{active_record.name.demodulize.underscore.pluralize}_count"
elsif options[:counter_cache]
options[:counter_cache]
end