lib/active_scaffold/finder.rb in active_scaffold-3.6.0.rc1 vs lib/active_scaffold/finder.rb in active_scaffold-3.6.0.rc2
- old
+ new
@@ -407,13 +407,13 @@
def active_scaffold_embedded_conditions
params_hash active_scaffold_embedded_params[:conditions]
end
- def all_conditions
+ def all_conditions(include_id_condition = true)
[
- id_condition, # for list with id (e.g. /users/:id/index)
+ (id_condition if include_id_condition), # for list with id (e.g. /users/:id/index)
active_scaffold_conditions, # from the search modules
conditions_for_collection, # from the dev
conditions_from_params, # from the parameters (e.g. /users/list?first_name=Fred)
conditions_from_constraints, # from any constraints (embedded scaffolds)
active_scaffold_embedded_conditions # embedding conditions (weaker constraints)
@@ -442,13 +442,15 @@
# * :per_page
# * :page
def finder_options(options = {})
search_conditions = all_conditions
+ sorting = options[:sorting]&.clause((grouped_columns_calculations if grouped_search?))
+ sorting = sorting.map(&Arel.method(:sql)) if sorting && active_scaffold_config.active_record?
# create a general-use options array that's compatible with Rails finders
finder_options = {
- :reorder => options[:sorting]&.clause((grouped_columns_calculations if grouped_search?)).map(&Arel.method(:sql)),
+ :reorder => sorting,
:conditions => search_conditions
}
if active_scaffold_config.mongoid?
finder_options[:includes] = [active_scaffold_references, active_scaffold_preload].compact.flatten.uniq.presence
else
@@ -517,11 +519,11 @@
def calculate_last_modified(query)
return unless conditional_get_support? && ActiveScaffold::OrmChecks.columns_hash(query.klass)['updated_at']
@last_modified = query.maximum(:updated_at)
end
- def calculate_query
- conditions = all_conditions
+ def calculate_query(id_condition = true)
+ conditions = all_conditions(id_condition)
includes = active_scaffold_config.list.count_includes
includes ||= active_scaffold_references if conditions.present?
left_joins = active_scaffold_outer_joins
left_joins += includes if includes
primary_key = active_scaffold_config.primary_key