提交 475d1d17 编写于 作者: P Pratik Naik

Use arel instead of sql strings

上级 1f675ea8
......@@ -113,12 +113,11 @@ def destroy #:nodoc:
lock_col = self.class.locking_column
previous_value = send(lock_col).to_i
affected_rows = connection.delete(
"DELETE FROM #{self.class.quoted_table_name} " +
"WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id} " +
"AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}",
"#{self.class.name} Destroy"
)
table = self.class.arel_table
predicate = table[self.class.primary_key].eq(id)
predicate = predicate.and(table[self.class.locking_column].eq(previous_value))
affected_rows = self.class.unscoped.where(predicate).delete_all
unless affected_rows == 1
raise ActiveRecord::StaleObjectError, "Attempted to delete a stale object: #{self.class.name}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册