From fb54b187dfccfac9d34a93d82e6f4fa9367f64a4 Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Fri, 20 Dec 2024 03:25:55 -0800 Subject: [PATCH] add_ids --- app/classes/query/initializers/observations.rb | 14 +++++++++++--- app/classes/query/location_with_observations.rb | 14 +------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/classes/query/initializers/observations.rb b/app/classes/query/initializers/observations.rb index 5a5e80fca3..bd2cfbb6b1 100644 --- a/app/classes/query/initializers/observations.rb +++ b/app/classes/query/initializers/observations.rb @@ -40,6 +40,14 @@ def observations_coercion_parameter_declarations } end + # This is just to allow the additional location conditions + def add_ids_condition(table = model.table_name, ids = :ids) + return if params[ids].nil? # [] is valid + + super + add_is_collection_location_condition_for_locations + end + def initialize_herbaria_parameter add_id_condition( "herbarium_records.herbarium_id", @@ -74,7 +82,7 @@ def add_for_project_condition @title_tag = :query_title_for_project @title_args[:project] = project.title where << "project_observations.project_id = '#{params[:project]}'" - add_collection_location_condition_for_locations + add_is_collection_location_condition_for_locations add_join(:observations, :project_observations) end @@ -101,11 +109,11 @@ def add_in_species_list_condition @title_tag = :query_title_in_species_list @title_args[:species_list] = spl.format_name where << "species_list_observations.species_list_id = '#{spl.id}'" - add_collection_location_condition_for_locations + add_is_collection_location_condition_for_locations add_join(:observations, :species_list_observations) end - def add_collection_location_condition_for_locations + def add_is_collection_location_condition_for_locations return unless model == Location where << "observations.is_collection_location IS TRUE" diff --git a/app/classes/query/location_with_observations.rb b/app/classes/query/location_with_observations.rb index ad7e7abd36..d620f0bb64 100644 --- a/app/classes/query/location_with_observations.rb +++ b/app/classes/query/location_with_observations.rb @@ -20,7 +20,7 @@ def parameter_declarations def initialize_flavor add_join(:observations) - add_ids_condition + add_ids_condition("observations", :obs_ids) add_owner_and_time_stamp_conditions("observations") add_by_user_condition("observations") add_date_condition("observations.when", params[:date]) @@ -34,18 +34,6 @@ def initialize_flavor super end - def add_ids_condition - return unless params[:obs_ids] - - set = clean_id_set(params[:obs_ids]) - @where << "observations.id IN (#{set})" - self.order = "FIND_IN_SET(observations.id,'#{set}') ASC" - - @title_args[:observations] = params[:old_title] || - :query_title_in_set.t(type: :observation) - where << "observations.is_collection_location IS TRUE" - end - def add_where_conditions add_where_condition(:observations, params[:locations]) add_at_location_parameter(:observations)