Displaying 2 results from an estimated 2 matches for "false_values".
2010 May 28
2
Suggestion for improving value_to_boolean column conversion
...nowing what
to do about them.
I will suggest to modify the existing implementation of
ActiveRecord::ConnectionAdapters::Column::value_to_boolean
to
ActiveRecord::ConnectionAdapters::Column.class_eval %q{
def self.value_to_boolean(value)
case value
when *TRUE_VALUES.to_a: true
when *FALSE_VALUES.to_a: false
else nil
end
end
}
First of all it simplifies the implementation (getting rid of initial
if. secondly it will at least result in nil if value is neither
recognised among TRUE_VALUES nor FALSE_VALUES
Jarl
--
You received this message because you are subscribed to the Google...
2010 Sep 02
1
ActiveRecord::ConnectionAdapters::Column value_to_boolean(value) does not return a boolean value.
...)
155: end
156: end
If value is contained in TRUE_VALUES then it returns true(TrueClass).
But if value is anything else it returns nil(NilClass) instead of
false(FalseClass)
This does not seem consistent or expected to me since false <> nil.
Since we have TRUE_VALUES and FALSE_VALUES, I think it should be
something like this.
150 def value_to_boolean(value)
151 if TRUE_VALUES.include?(value)
152 true
153 elsif FALSE_VALUES.include?(value)
154 false
155 else
156 nil
157 end
158 end
--
You recei...