1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

changed update counter to act on unscoped model

This commit is contained in:
heruku 2013-11-24 03:47:17 -06:00 committed by dbc-apprentice
parent 3669704050
commit 45d4d141f9
4 changed files with 19 additions and 1 deletions

View file

@ -1,3 +1,9 @@
* Update counter cache on a has_many relationship regardless of default scope
Fix #12952.
*Uku Taht*
* `rename_index` adds the new index before removing the old one. This allows
to rename indexes on columns with a foreign key and prevents the following error:

View file

@ -77,7 +77,7 @@ module ActiveRecord
"#{quoted_column} = COALESCE(#{quoted_column}, 0) #{operator} #{value.abs}"
end
where(primary_key => id).update_all updates.join(', ')
unscoped.where(primary_key => id).update_all updates.join(', ')
end
# Increment a numeric field by one, via a direct SQL update.

View file

@ -1781,4 +1781,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [original_child], car.reload.failed_bulbs
end
test 'updates counter cache when default scope is given' do
topic = DefaultRejectedTopic.create approved: true
assert_difference "topic.reload.replies_count", 1 do
topic.approved_replies.create!
end
end
end

View file

@ -106,6 +106,10 @@ class ImportantTopic < Topic
serialize :important, Hash
end
class DefaultRejectedTopic < Topic
default_scope -> { where(approved: false) }
end
class BlankTopic < Topic
# declared here to make sure that dynamic finder with a bang can find a model that responds to `blank?`
def blank?