lib/query_helper.rb in query_helper-0.3.8 vs lib/query_helper.rb in query_helper-0.4.0

- old
+ new

@@ -8,11 +8,10 @@ require "query_helper/sql_parser" require "query_helper/sql_manipulator" require "query_helper/sql_filter" require "query_helper/sql_sort" require "query_helper/invalid_query_error" -require "query_helper/invalid_sort_param_error" class QueryHelper attr_accessor :model, :bind_variables, :sql_filter, :sql_sort, :page, :per_page, :single_record, :associations, :as_json_options, :executed_query, :api_payload, :preload, :search_field, :search_string, :metadata attr_reader :query @@ -279,11 +278,15 @@ def search_filter(column_maps) raise ArgumentError.new("search_fields not defined") unless @search_fields.length > 0 placement = :where maps = column_maps.select do |cm| - placement = :having if cm.aggregate - @search_fields.map(&:downcase).include? cm.alias_name.downcase + if @search_fields.include? cm.alias_name + placement = :having if cm.aggregate + true + else + false + end end bind_variable = ('a'..'z').to_a.shuffle[0,20].join.to_sym @bind_variables[bind_variable] = "%#{@search_string}%" filter = "#{maps.map{|m| "coalesce(#{m.sql_expression}::varchar, '')"}.join(" || ")} ilike :#{bind_variable}" return {