aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/string.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-09 20:38:40 -0700
committerSean Griffin <sean@thoughtbot.com>2014-11-09 20:42:36 -0700
commit52c3a16fa07cde643af3c2200e4b87bcb470eb12 (patch)
tree9198c2872f832080d0d32e263cfe1e2ddd8dd4cb /activerecord/lib/active_record/type/string.rb
parentcb0ba2f2b144d15e825cf890ea9bc7e322d25349 (diff)
downloadrails-52c3a16fa07cde643af3c2200e4b87bcb470eb12.tar.gz
rails-52c3a16fa07cde643af3c2200e4b87bcb470eb12.tar.bz2
rails-52c3a16fa07cde643af3c2200e4b87bcb470eb12.zip
Revert the behavior of booleans in string columns to that of 4.1
Why are people assigning booleans to string columns? >_> We unintentionally changed the behavior on Sqlite3 and PostgreSQL. Boolean values should cast to the database's representation of true and false. This is 't' and 'f' by default, and "1" and "0" on Mysql. The implementation to make the connection adapter specific behavior is hacky at best, and should be re-visted once we decide how we actually want to separate the concerns related to things that should change based on the database adapter. That said, this isn't something I'd expect to change based on my database adapter. We're storing a string, so the way the database represents a boolean should be irrelevant. It also seems strange for us to give booleans special behavior at all in string columns. Why is `to_s` not sufficient? It's inconsistent and confusing. Perhaps we should consider deprecating in the future. Fixes #17571
Diffstat (limited to 'activerecord/lib/active_record/type/string.rb')
-rw-r--r--activerecord/lib/active_record/type/string.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb
index 150defb106..fbc0af2c5a 100644
--- a/activerecord/lib/active_record/type/string.rb
+++ b/activerecord/lib/active_record/type/string.rb
@@ -15,8 +15,8 @@ module ActiveRecord
case value
when ::Numeric, ActiveSupport::Duration then value.to_s
when ::String then ::String.new(value)
- when true then "1"
- when false then "0"
+ when true then "t"
+ when false then "f"
else super
end
end
@@ -25,8 +25,8 @@ module ActiveRecord
def cast_value(value)
case value
- when true then "1"
- when false then "0"
+ when true then "t"
+ when false then "f"
# String.new is slightly faster than dup
else ::String.new(value.to_s)
end