From bcc67f0cf6374ba0554c7e8f73120d004d991f35 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 20 Jul 2022 14:07:52 -0400 Subject: [PATCH] fix snapshot queries --- app/controllers/people_controller.rb | 38 +++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 2e141c88b..76878ab50 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -375,8 +375,8 @@ def includes def references [ :email_addresses, - :convention_roles, - {person_schedule_approvals: {schedule_workflow: :schedule_snapshot}} + :convention_roles + # {person_schedule_approvals: {schedule_workflow: :schedule_snapshot}} ] end @@ -397,10 +397,10 @@ def subquery(operation:, value:) def get_table(column:) if column.include?('draft_person_schedule_approvals') - return PersonScheduleApproval.arel_table + return PersonScheduleApproval.arel_table #.alias('draft_approvals') end if column.include?('firm_person_schedule_approvals') - return PersonScheduleApproval.arel_table + return PersonScheduleApproval.arel_table #.alias('firm_approvals') end return super(column: column) @@ -418,14 +418,34 @@ def get_query_part(table:, column:, operation:, value:, top: false, key: nil) end def approval_query(table:, column:, operation:, value:, label:) - op = translate_operator(operation: operation) + people = Person.arel_table schedule_snapshots = ScheduleSnapshot.arel_table - part = table[column.to_sym].send(op, value).and(schedule_snapshots[:label].eq(label)) + schedule_workflows = ScheduleWorkflow.arel_table if value == 'not_set' - part = part.or(table[column.to_sym].eq(nil)) + people[:id].not_in( + table.project(:person_id) + .join( + schedule_workflows, + Arel::Nodes::OuterJoin + ) + .on(table[:schedule_workflow_id].eq(schedule_workflows[:id])) + .where( + schedule_workflows[:state].eq(label).and(table[:approved].eq('yes')).or(table[:approved].eq('no')) + ) + ) + else + people[:id].in( + table.project(:person_id) + .join( + schedule_workflows, + Arel::Nodes::OuterJoin + ) + .on(table[:schedule_workflow_id].eq(schedule_workflows[:id])) + .where( + schedule_workflows[:state].eq(label).and(table[:approved].eq(value)) + ) + ) end - - return part end