diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-08-07 18:56:49 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-02-23 13:42:16 +0100 |
commit | d9314b4c0a8b32f242ed4d394dcc3d45ddfb4c62 (patch) | |
tree | c6645aed37294bb168362b15c014ec68f68ab118 /activerecord/lib/active_record/connection_adapters/column.rb | |
parent | 96759cf6c6a17053abb6a2b7cd87cdbd5a8420ba (diff) | |
download | rails-d9314b4c0a8b32f242ed4d394dcc3d45ddfb4c62.tar.gz rails-d9314b4c0a8b32f242ed4d394dcc3d45ddfb4c62.tar.bz2 rails-d9314b4c0a8b32f242ed4d394dcc3d45ddfb4c62.zip |
Coerce strings when reading attributes.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/column.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 10 |
1 files changed, 8 insertions, 2 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) |