提交 ead0c6ee 编写于 作者: A Aaron Patterson

removing more calls to deprecated methods

上级 12b9920a
...@@ -67,9 +67,10 @@ def delete_records(records) ...@@ -67,9 +67,10 @@ def delete_records(records)
@reflection.klass.delete(records.map { |record| record.id }) @reflection.klass.delete(records.map { |record| record.id })
else else
relation = Arel::Table.new(@reflection.table_name) relation = Arel::Table.new(@reflection.table_name)
relation.where(relation[@reflection.primary_key_name].eq(@owner.id). stmt = relation.where(relation[@reflection.primary_key_name].eq(@owner.id).
and(relation[@reflection.klass.primary_key].in(records.map { |r| r.id })) and(relation[@reflection.klass.primary_key].in(records.map { |r| r.id }))
).update(relation[@reflection.primary_key_name] => nil) ).compile_update(relation[@reflection.primary_key_name] => nil)
@owner.connection.update stmt.to_sql
@owner.class.update_counters(@owner.id, cached_counter_attribute_name => -records.size) if has_cached_counter? @owner.class.update_counters(@owner.id, cached_counter_attribute_name => -records.size) if has_cached_counter?
end end
......
...@@ -30,9 +30,10 @@ def reset_counters(id, *counters) ...@@ -30,9 +30,10 @@ def reset_counters(id, *counters)
reflection = belongs_to.find { |e| e.class_name == expected_name } reflection = belongs_to.find { |e| e.class_name == expected_name }
counter_name = reflection.counter_cache_column counter_name = reflection.counter_cache_column
self.unscoped.where(arel_table[self.primary_key].eq(object.id)).arel.update({ stmt = unscoped.where(arel_table[primary_key].eq(object.id)).arel.compile_update({
arel_table[counter_name] => object.send(association).count arel_table[counter_name] => object.send(association).count
}) })
connection.update stmt.to_sql
end end
return true return true
end end
......
...@@ -156,7 +156,8 @@ def update_all(updates, conditions = nil, options = {}) ...@@ -156,7 +156,8 @@ def update_all(updates, conditions = nil, options = {})
else else
# Apply limit and order only if they're both present # Apply limit and order only if they're both present
if @limit_value.present? == @order_values.present? if @limit_value.present? == @order_values.present?
arel.update(Arel::SqlLiteral.new(@klass.send(:sanitize_sql_for_assignment, updates))) stmt = arel.compile_update(Arel::SqlLiteral.new(@klass.send(:sanitize_sql_for_assignment, updates)))
@klass.connection.update stmt.to_sql
else else
except(:limit, :order).update_all(updates) except(:limit, :order).update_all(updates)
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册