Method: Caprese::Query#queried_record_scope

Defined in:
lib/caprese/controller/concerns/query.rb

#queried_record_scopeRelation

Gets the scope by which to query controller records, taking into account custom scoping and the filters provided in the query

Returns:

  • (Relation)

    the record scope of the queried controller



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/caprese/controller/concerns/query.rb', line 202

def queried_record_scope
  unless @queried_record_scope
    scope = record_scope(unnamespace(params[:controller]).to_sym)

    if scope.any? && query_params[:filter].try(:any?)
      if (valid_filters = query_params[:filter].select { |k, _| scope.column_names.include? actual_field(k).to_s }).present?
        valid_filters.each do |k, v|
          scope = scope.where(actual_field(k) => v)
        end
      end
    end

    @queried_record_scope = scope
  end

  @queried_record_scope
end