diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-01-02 21:10:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-02 21:10:32 +0100 |
commit | 33e60514aed85b3076f2636d5f1ccfb513aace1c (patch) | |
tree | 56953381ef0764357f22d0ce497400ee43a5598f /activerecord/lib/active_record/counter_cache.rb | |
parent | 4bf04471f525571146f238e200467724b25689d8 (diff) | |
parent | 059a476c570bc3451df855b99724e74bc2cba604 (diff) | |
download | rails-33e60514aed85b3076f2636d5f1ccfb513aace1c.tar.gz rails-33e60514aed85b3076f2636d5f1ccfb513aace1c.tar.bz2 rails-33e60514aed85b3076f2636d5f1ccfb513aace1c.zip |
Merge pull request #27543 from kamipo/fix_update_counters_of_multiple_records_with_touch
Fix update counters of multiple records with touch: true
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index c654d4703a..93b9371206 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -46,7 +46,7 @@ module ActiveRecord counter_name = reflection.counter_cache_column updates = { counter_name.to_sym => object.send(counter_association).count(:all) } - updates.merge!(touch_updates(object, touch)) if touch + updates.merge!(touch_updates(touch)) if touch unscoped.where(primary_key => object.id).update_all(updates) end @@ -105,8 +105,7 @@ module ActiveRecord end if touch - object = find(id) - updates << object.class.send(:sanitize_sql_for_assignment, touch_updates(object, touch)) + updates << sanitize_sql_for_assignment(touch_updates(touch)) end unscoped.where(primary_key => id).update_all updates.join(", ") @@ -165,9 +164,9 @@ module ActiveRecord end private - def touch_updates(object, touch) - touch = object.send(:timestamp_attributes_for_update_in_model) if touch == true - touch_time = object.send(:current_time_from_proper_timezone) + def touch_updates(touch) + touch = timestamp_attributes_for_update_in_model if touch == true + touch_time = current_time_from_proper_timezone Array(touch).map { |column| [ column, touch_time ] }.to_h end end |