aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/quoting.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb24
1 files changed, 7 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 04ae67234f..143d7d9574 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -9,13 +9,8 @@ module ActiveRecord
# records are quoted as their primary key
return value.quoted_id if value.respond_to?(:quoted_id)
- # FIXME: The only case we get an object other than nil or a real column
- # is `SchemaStatements#add_column` with a PG array that has a non-empty default
- # value. Is this really the only case? Are we missing tests for other types?
- # We should have a real column object passed (or nil) here, and check for that
- # instead
- if column.respond_to?(:type_cast_for_database)
- value = column.type_cast_for_database(value)
+ if column
+ value = column.cast_type.type_cast_for_database(value)
end
_quote(value)
@@ -24,18 +19,13 @@ module ActiveRecord
# Cast a +value+ to a type that the database understands. For example,
# SQLite does not understand dates, so this method will convert a Date
# to a String.
- def type_cast(value, column)
+ def type_cast(value, column = nil)
if value.respond_to?(:quoted_id) && value.respond_to?(:id)
return value.id
end
- # FIXME: The only case we get an object other than nil or a real column
- # is `SchemaStatements#add_column` with a PG array that has a non-empty default
- # value. Is this really the only case? Are we missing tests for other types?
- # We should have a real column object passed (or nil) here, and check for that
- # instead
- if column.respond_to?(:type_cast_for_database)
- value = column.type_cast_for_database(value)
+ if column
+ value = column.cast_type.type_cast_for_database(value)
end
_type_cast(value)
@@ -66,7 +56,7 @@ module ActiveRecord
# This works for mysql and mysql2 where table.column can be used to
# resolve ambiguity.
#
- # We override this in the sqlite and postgresql adapters to use only
+ # We override this in the sqlite3 and postgresql adapters to use only
# the column name (as per syntax requirements).
def quote_table_name_for_assignment(table, attr)
quote_table_name("#{table}.#{attr}")
@@ -118,7 +108,7 @@ module ActiveRecord
when Numeric, ActiveSupport::Duration then value.to_s
when Date, Time then "'#{quoted_date(value)}'"
when Symbol then "'#{quote_string(value.to_s)}'"
- when Class then "'#{value.to_s}'"
+ when Class then "'#{value}'"
else
"'#{quote_string(YAML.dump(value))}'"
end