aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-12-12 14:26:10 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-12-12 14:33:01 -0800
commite2be6eacb86aa11f2c606d45a639802e946e911a (patch)
tree090e1ac7b937a8daf61f46a926efc07d30cae4ea /activerecord
parent45940e7112cab8414b15baeb4ef5783247e9f576 (diff)
downloadrails-e2be6eacb86aa11f2c606d45a639802e946e911a.tar.gz
rails-e2be6eacb86aa11f2c606d45a639802e946e911a.tar.bz2
rails-e2be6eacb86aa11f2c606d45a639802e946e911a.zip
remove duplicate code
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb21
1 files changed, 6 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index 5ce2a5dcb7..625a2efabd 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -15,7 +15,7 @@ module ActiveRecord
set_inverse_instance(record)
@updated = true
else
- update_counters_without_record
+ decrement_counters
remove_keys
end
@@ -41,19 +41,6 @@ module ActiveRecord
counter_cache_name = reflection.counter_cache_column
return unless counter_cache_name && owner.persisted?
-
- update_with_record record, counter_cache_name
- end
-
- def update_counters_without_record
- counter_cache_name = reflection.counter_cache_column
-
- return unless counter_cache_name && owner.persisted?
-
- update_without_record counter_cache_name
- end
-
- def update_with_record record, counter_cache_name
return unless different_target? record
record.class.increment_counter(counter_cache_name, record.id)
@@ -61,7 +48,11 @@ module ActiveRecord
decrement_counter counter_cache_name
end
- def update_without_record counter_cache_name
+ def decrement_counters
+ counter_cache_name = reflection.counter_cache_column
+
+ return unless counter_cache_name && owner.persisted?
+
decrement_counter counter_cache_name
end