diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-12-12 14:23:28 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-12-12 14:33:01 -0800 |
commit | 45940e7112cab8414b15baeb4ef5783247e9f576 (patch) | |
tree | 832e516a5b8b09624f8f364fb79ecb84d41bce32 /activerecord/lib | |
parent | 9798a11c2bc9cef5d66efe5006b607c9d858da76 (diff) | |
download | rails-45940e7112cab8414b15baeb4ef5783247e9f576.tar.gz rails-45940e7112cab8414b15baeb4ef5783247e9f576.tar.bz2 rails-45940e7112cab8414b15baeb4ef5783247e9f576.zip |
extract a method for updating without a record object
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/belongs_to_association.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 2c5ad9d1c0..5ce2a5dcb7 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(record) + update_counters_without_record remove_keys end @@ -42,11 +42,15 @@ module ActiveRecord return unless counter_cache_name && owner.persisted? - if record - update_with_record record, counter_cache_name - else - update_without_record counter_cache_name - end + 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 |