lib/model-api/api_context.rb
def apply_filter_param(attr_metadata, collection, opts = {})
      raw_value = (opts[:attr_values] || params)[attr_metadata[:key]]
      filter_table = opts[:filter_table]
      klass = opts[:class] || ModelApi::Utils.find_class(collection, opts)
      if raw_value.is_a?(Hash) && raw_value.include?('0')
        operator_value_pairs = filter_process_param_array(params_array(raw_value), attr_metadata,
            opts)
      else
        operator_value_pairs = filter_process_param(raw_value, attr_metadata, opts)
      end
      if (column = resolve_key_to_column(klass, attr_metadata)).present?
        operator_value_pairs.each do |operator, value|
          if operator == '=' && filter_table.blank?
            collection = collection.where(column => value)
          else
            table_name = (filter_table || klass.table_name).to_s.delete('`')
            column = column.to_s.delete('`')
            if value.is_a?(Array)
              operator = 'IN'
              value = value.map { |_v| format_value_for_query(column, value, klass) }
              value = "(#{value.map { |v| "'#{v.to_s.gsub("'", "''")}'" }.join(',')})"
            else
              value = "'#{value.gsub("'", "''")}'"
            end
            collection = collection.where("`#{table_name}`.`#{column}` #{operator} #{value}")
          end
        end
      elsif (key = attr_metadata[:key]).present?
        opts[:result_filters][key] = operator_value_pairs if opts.include?(:result_filters)
      end
      collection
    end
def apply_filter_param(attr_metadata, collection, opts = {})
      raw_value = (opts[:attr_values] || params)[attr_metadata[:key]]
      filter_table = opts[:filter_table]
      klass = opts[:class] || ModelApi::Utils.find_class(collection, opts)
      if raw_value.is_a?(Hash) && raw_value.include?('0')
        operator_value_pairs = filter_process_param_array(params_array(raw_value), attr_metadata,
            opts)
      else
        operator_value_pairs = filter_process_param(raw_value, attr_metadata, opts)
      end
      if (column = resolve_key_to_column(klass, attr_metadata)).present?
        operator_value_pairs.each do |operator, value|
          if operator == '=' && filter_table.blank?
            collection = collection.where(column => value)
          else
            table_name = (filter_table || klass.table_name).to_s.delete('`')
            column = column.to_s.delete('`')
            if value.is_a?(Array)
              operator = 'IN'
              value = value.map { |_v| format_value_for_query(column, value, klass) }
              value = "(#{value.map { |v| "'#{v.to_s.gsub("'", "''")}'" }.join(',')})"
            else
              value = "'#{value.gsub("'", "''")}'"
            end
            collection = collection.where("`#{table_name}`.`#{column}` #{operator} #{value}")
          end
        end
      elsif (key = attr_metadata[:key]).present?
        opts[:result_filters][key] = operator_value_pairs if opts.include?(:result_filters)
      end
      collection
    end
rubocop:enable Metrics/ParameterLists