Skip to content

Commit

Permalink
unfortunately ActiveRecord does casting *all over the place* so I nee…
Browse files Browse the repository at this point in the history
…d to also fully override type_cast_code as well
  • Loading branch information
brianmario committed May 13, 2010
1 parent af2dd0d commit e01c758
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/active_record/connection_adapters/mysql2_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,18 @@ def type_cast(value)

def type_cast_code(var_name)
case type
when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})"
else
nil
when :string then nil
when :text then nil
when :integer then "(#{var_name}.is_a?(Fixnum) ? #{var_name} : (#{var_name}.to_i rescue value ? 1 : 0))"
when :float then "#{var_name}.class == Float ? #{var_name} : #{var_name}.to_f"
when :decimal then "#{var_name}.class == BigDecimal ? #{var_name} : #{self.class.name}.value_to_decimal(#{var_name})"
when :datetime then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_time(#{var_name})"
when :timestamp then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_time(#{var_name})"
when :time then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_dummy_time(#{var_name})"
when :date then "#{var_name}.class == Date ? #{var_name} : #{self.class.name}.string_to_date(#{var_name})"
when :binary then nil
when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})"
else nil
end
end

Expand Down

0 comments on commit e01c758

Please sign in to comment.