aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb13
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 =~ /\((.*)\)/