提交 2f0c8c52 编写于 作者: J Jon Leighton

remove deprecate #update_all usage

上级 1606bee6
......@@ -69,7 +69,7 @@ def update_counters(id, counters)
"#{quoted_column} = COALESCE(#{quoted_column}, 0) #{operator} #{value.abs}"
end
update_all(updates.join(', '), primary_key => id)
where(primary_key => id).update_all updates.join(', ')
end
# Increment a number field by one, usually representing a count.
......
......@@ -178,7 +178,7 @@ def update_column(name, value)
verify_readonly_attribute(name)
raise ActiveRecordError, "can not update on a new record object" unless persisted?
raw_write_attribute(name, value)
self.class.update_all({ name => value }, self.class.primary_key => id) == 1
self.class.where(self.class.primary_key => id).update_all(name => value) == 1
end
# Updates the attributes of the model from the passed-in hash and saves the
......@@ -313,7 +313,7 @@ def touch(name = nil)
@changed_attributes.except!(*changes.keys)
primary_key = self.class.primary_key
self.class.unscoped.update_all(changes, { primary_key => self[primary_key] }) == 1
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
end
end
......
......@@ -288,7 +288,7 @@ def test_partial_update
with_partial_updates Pirate, false do
assert_queries(2) { 2.times { pirate.save! } }
Pirate.update_all({ :updated_on => old_updated_on }, :id => pirate.id)
Pirate.where(id: pirate.id).update_all(:updated_on => old_updated_on)
end
with_partial_updates Pirate, true do
......@@ -306,7 +306,7 @@ def test_partial_update_with_optimistic_locking
with_partial_updates Person, false do
assert_queries(2) { 2.times { person.save! } }
Person.update_all({ :first_name => 'baz' }, :id => person.id)
Person.where(id: person.id).update_all(:first_name => 'baz')
end
with_partial_updates Person, true do
......
......@@ -94,12 +94,6 @@ def test_delete_all_with_joins_and_where_part_is_not_hash
assert_equal count, Pet.joins(:toys).where(where_args).delete_all
end
def test_update_by_condition
Topic.update_all "content = 'bulk updated!'", ["approved = ?", true]
assert_equal "Have a nice day", Topic.find(1).content
assert_equal "bulk updated!", Topic.find(2).content
end
def test_increment_attribute
assert_equal 50, accounts(:signals37).credit_limit
accounts(:signals37).increment! :credit_limit
......@@ -338,7 +332,7 @@ def test_update_all_with_hash
end
def test_update_all_with_non_standard_table_name
assert_equal 1, WarehouseThing.update_all(['value = ?', 0], ['id = ?', 1])
assert_equal 1, WarehouseThing.where(id: 1).update_all(['value = ?', 0])
assert_equal 0, WarehouseThing.find(1).value
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册