instance method
attributes_with_quotes
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18 PrivateAvailable in: v2.2.3 v2.3.18
Signature
attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
Returns a copy of the attributes hash where all the values have been safely quoted for use in an SQL statement.
Parameters
-
include_primary_keyopt = true -
include_readonly_attributesopt = true -
attribute_namesopt = @attributes.keys
Source
# File activerecord/lib/active_record/base.rb, line 2807
def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
quoted = {}
connection = self.class.connection
attribute_names.each do |name|
if (column = column_for_attribute(name)) && (include_primary_key || !column.primary)
value = read_attribute(name)
# We need explicit to_yaml because quote() does not properly convert Time/Date fields to YAML.
if value && self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))
value = value.to_yaml
end
quoted[name] = connection.quote(value, column)
end
end
include_readonly_attributes ? quoted : remove_readonly_attributes(quoted)
end
Defined in activerecord/lib/active_record/base.rb line 2807
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base