module ActiveSet::Filtering::ActiveRecord::QueryColumn

Public Instance Methods

query_column() click to toggle source
# File lib/active_set/filtering/active_record/query_column.rb, line 7
def query_column
  return @query_column if defined? @query_column

  @query_column = if must_cast_numerical_column?
                    column_cast_as_char
                  else
                    arel_column
                  end
end

Private Instance Methods

column_cast_as_char() click to toggle source
# File lib/active_set/filtering/active_record/query_column.rb, line 19
def column_cast_as_char
  # In order to use LIKE, we must CAST the numeric column as a CHAR column.
  # NOTE: this is can be quite inefficient, as it forces the DB engine to perform that cast on all rows.
  # https://www.ryadel.com/en/like-operator-equivalent-integer-numeric-columns-sql-t-sql-database/
  Arel::Nodes::NamedFunction.new('CAST', [arel_column.as('CHAR')])
end
must_cast_numerical_column?() click to toggle source
# File lib/active_set/filtering/active_record/query_column.rb, line 26
def must_cast_numerical_column?
  # The LIKE operator can't be used if the column hosts numeric types.
  return false unless arel_type.presence_in(%i[integer float])

  arel_operator.to_s.downcase.include?('match')
end