aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/column.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-02-24 08:26:49 +0100
committerYves Senn <yves.senn@gmail.com>2014-02-24 08:26:49 +0100
commit0e144bebc6d979780c3243537673ff553ffb37f5 (patch)
treec797ae18c38f740b84e46f8df16870e45c1e1066 /activerecord/lib/active_record/connection_adapters/column.rb
parent4d24c150ab575db3980d1999c82806c9375b8b5f (diff)
parentd9314b4c0a8b32f242ed4d394dcc3d45ddfb4c62 (diff)
downloadrails-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/connection_adapters/column.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb10
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)