AlexanderPavlenko
2/4/2013 - 1:15 PM

fix PostgreSQL comparison of string and number

fix PostgreSQL comparison of string and number

module Arel::Visitors
  class ToSql
    alias :visit_Fixnum :quoted
    alias :visit_Bignum :quoted
  end
end

module ActiveRecord::ConnectionAdapters
  class PostgreSQLAdapter
    module FixNumberToStringComparison
      def quote(value, column)
        if value.is_a?(Numeric) && column.type == :string
          "'#{value}'"
        else
          super
        end
      end
    end
    include FixNumberToStringComparison
  end
end