+ def apply_where_limit_order_params
+ ar_table_name = @objects.table_name
+
+ ft = record_filters @filters, ar_table_name
+ if ft[:cond_out].any?
+ @objects = @objects.where(ft[:cond_out].join(' AND '), *ft[:param_out])
+ end
+
+ if @where.is_a? Hash and @where.any?
+ conditions = ['1=1']
+ @where.each do |attr,value|
+ if attr.to_s == 'any'
+ if value.is_a?(Array) and
+ value.length == 2 and
+ value[0] == 'contains' then
+ ilikes = []
+ model_class.searchable_columns('ilike').each do |column|
+ # Including owner_uuid in an "any column" search will
+ # probably just return a lot of false positives.
+ next if column == 'owner_uuid'
+ ilikes << "#{ar_table_name}.#{column} ilike ?"
+ conditions << "%#{value[1]}%"
+ end
+ if ilikes.any?
+ conditions[0] << ' and (' + ilikes.join(' or ') + ')'
+ end
+ end
+ elsif attr.to_s.match(/^[a-z][_a-z0-9]+$/) and
+ model_class.columns.collect(&:name).index(attr.to_s)
+ if value.nil?
+ conditions[0] << " and #{ar_table_name}.#{attr} is ?"
+ conditions << nil
+ elsif value.is_a? Array
+ if value[0] == 'contains' and value.length == 2
+ conditions[0] << " and #{ar_table_name}.#{attr} like ?"
+ conditions << "%#{value[1]}%"
+ else
+ conditions[0] << " and #{ar_table_name}.#{attr} in (?)"
+ conditions << value
+ end
+ elsif value.is_a? String or value.is_a? Fixnum or value == true or value == false
+ conditions[0] << " and #{ar_table_name}.#{attr}=?"
+ conditions << value
+ elsif value.is_a? Hash
+ # Not quite the same thing as "equal?" but better than nothing?
+ value.each do |k,v|
+ if v.is_a? String
+ conditions[0] << " and #{ar_table_name}.#{attr} ilike ?"
+ conditions << "%#{k}%#{v}%"
+ end
+ end
+ end
+ end
+ end
+ if conditions.length > 1
+ conditions[0].sub!(/^1=1 and /, '')
+ @objects = @objects.
+ where(*conditions)
+ end
+ end
+
+ @objects = @objects.select(@select.map { |s| "#{table_name}.#{ActiveRecord::Base.connection.quote_column_name s.to_s}" }.join ", ") if @select
+ @objects = @objects.order(@orders.join ", ") if @orders.any?
+ @objects = @objects.limit(@limit)
+ @objects = @objects.offset(@offset)
+ @objects = @objects.uniq(@distinct) if not @distinct.nil?
+ end
+