diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-02-24 08:26:49 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-02-24 08:26:49 +0100 |
commit | 0e144bebc6d979780c3243537673ff553ffb37f5 (patch) | |
tree | c797ae18c38f740b84e46f8df16870e45c1e1066 /activerecord/lib/active_record | |
parent | 4d24c150ab575db3980d1999c82806c9375b8b5f (diff) | |
parent | d9314b4c0a8b32f242ed4d394dcc3d45ddfb4c62 (diff) | |
download | rails-0e144bebc6d979780c3243537673ff553ffb37f5.tar.gz rails-0e144bebc6d979780c3243537673ff553ffb37f5.tar.bz2 rails-0e144bebc6d979780c3243537673ff553ffb37f5.zip |
Merge pull request #10497 from senny/10485_does_not_coerce_strings
coerce strings when reading attributes
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid.rb | 18 |
2 files changed, 21 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index f2fbd5a8f2..187eefb9e4 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -87,7 +87,7 @@ module ActiveRecord end end - # Casts value (which is a String) to an appropriate instance. + # Casts value to an appropriate instance. def type_cast(value) return nil if value.nil? return coder.load(value) if encoded? @@ -95,7 +95,13 @@ module ActiveRecord klass = self.class case type - when :string, :text then value + when :string, :text + case value + when TrueClass; "1" + when FalseClass; "0" + else + value.to_s + end when :integer then klass.value_to_integer(value) when :float then value.to_f when :decimal then klass.value_to_decimal(value) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 6f9b60b6c4..e7df073627 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -18,6 +18,14 @@ module ActiveRecord end end + class Text < Type + def type_cast(value) + return if value.nil? + + value.to_s + end + end + class Bit < Type def type_cast(value) if String === value @@ -329,7 +337,7 @@ This is not reliable and will be removed in the future. alias_type 'oid', 'int2' register_type 'numeric', OID::Decimal.new - register_type 'text', OID::Identity.new + register_type 'text', OID::Text.new alias_type 'varchar', 'text' alias_type 'char', 'text' alias_type 'bpchar', 'text' @@ -355,13 +363,13 @@ This is not reliable and will be removed in the future. register_type 'date', OID::Date.new register_type 'time', OID::Time.new - register_type 'path', OID::Identity.new + register_type 'path', OID::Text.new register_type 'point', OID::Point.new - register_type 'polygon', OID::Identity.new - register_type 'circle', OID::Identity.new + register_type 'polygon', OID::Text.new + register_type 'circle', OID::Text.new register_type 'hstore', OID::Hstore.new register_type 'json', OID::Json.new - register_type 'ltree', OID::Identity.new + register_type 'ltree', OID::Text.new register_type 'cidr', OID::Cidr.new alias_type 'inet', 'cidr' |