diff options
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index ee4f818cbf..faaedf1d4a 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -111,7 +111,13 @@ module ActiveRecord updates << sanitize_sql_for_assignment(touch_updates) unless touch_updates.empty? end - unscoped.where(primary_key => id).update_all updates.join(", ") + if id.is_a?(Relation) && self == id.klass + relation = id + else + relation = unscoped.where!(primary_key => id) + end + + relation.update_all updates.join(", ") end # Increment a numeric field by one, via a direct SQL update. |