diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-19 09:53:36 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-19 09:53:36 +0000 |
commit | 2ed6d365bbb2a3e0138add33be964d1cc1705b76 (patch) | |
tree | 52cebc950df6630ed447aa927a3e4f3209ab74e4 /activerecord/lib | |
parent | d777e506f27debdb5c66cc6653e2f3dc1b634d88 (diff) | |
download | rails-2ed6d365bbb2a3e0138add33be964d1cc1705b76.tar.gz rails-2ed6d365bbb2a3e0138add33be964d1cc1705b76.tar.bz2 rails-2ed6d365bbb2a3e0138add33be964d1cc1705b76.zip |
Correct boolean handling in generated reader methods. References #2945.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3092 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 5be344ad06..df79f27576 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -59,7 +59,7 @@ module ActiveRecord when :time then self.class.string_to_dummy_time(value) when :date then self.class.string_to_date(value) when :binary then self.class.binary_to_string(value) - when :boolean then value == true or (value =~ /^t(rue)?$/i) == 0 or value.to_s == '1' + when :boolean then self.class.value_to_boolean(value) else value end end @@ -75,7 +75,7 @@ module ActiveRecord when :time then "#{self.class.name}.string_to_dummy_time(#{var_name})" when :date then "#{self.class.name}.string_to_date(#{var_name})" when :binary then "#{self.class.name}.binary_to_string(#{var_name})" - when :boolean then "(#{var_name} == true or (#{var_name} =~ /^t(?:true)?$/i) == 0 or #{var_name}.to_s == '1')" + when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})" else nil end end @@ -120,6 +120,15 @@ module ActiveRecord Time.send(Base.default_timezone, *time_array) rescue nil end + # convert something to a boolean + def self.value_to_boolean(value) + return value if value==true || value==false + case value.to_s.downcase + when "true", "t", "1" then true + else false + end + end + private def extract_limit(sql_type) $1.to_i if sql_type =~ /\((.*)\)/ |