Revision b304788d
Added by Amos Benari almost 12 years ago
- ID b304788d433a4d6fa1c049675d0113d80cc45373
lib/core_extensions.rb | ||
---|---|---|
|
||
def update_single_attribute(attribute, value)
|
||
connection.update(
|
||
"UPDATE #{self.class.table_name} " +
|
||
"SET #{attribute.to_s} = #{value} " +
|
||
"WHERE #{self.class.primary_key} = #{id}",
|
||
"UPDATE #{self.class.quoted_table_name} SET " +
|
||
"#{connection.quote_column_name(attribute.to_s)} = #{quote_value(value)} " +
|
||
"WHERE #{self.class.quoted_primary_key} = #{quote_value(id)}",
|
||
"#{self.class.name} Attribute Update"
|
||
)
|
||
end
|
||
|
||
def update_multiple_attribute(attributes)
|
||
connection.update(
|
||
"UPDATE #{self.class.table_name} SET " +
|
||
attributes.map{|key, value| " #{key.to_s} = #{value} "}.join(', ') +
|
||
"WHERE #{self.class.primary_key} = #{id}",
|
||
"UPDATE #{self.class.quoted_table_name} SET " +
|
||
attributes.map{|key, value| " #{connection.quote_column_name(key.to_s)} = #{quote_value(value)} " }.join(', ') +
|
||
"WHERE #{self.class.quoted_primary_key} = #{quote_value(id)}",
|
||
"#{self.class.name} Attribute Update"
|
||
)
|
||
end
|
||
|
||
# ActiveRecord Callback class
|
||
class EnsureNotUsedBy
|
||
attr_reader :klasses, :logger
|
Also available in: Unified diff
fixes #1729 safer migration code.