diff --git a/app/legacy_lib/nonprofit_query_generator.rb b/app/legacy_lib/nonprofit_query_generator.rb index f0ce820b8..a01542b17 100644 --- a/app/legacy_lib/nonprofit_query_generator.rb +++ b/app/legacy_lib/nonprofit_query_generator.rb @@ -16,9 +16,14 @@ def supporters def supporter_notes Qx.select("supporter_notes.*").from(:supporters).join(:supporter_notes, "supporters.id = supporter_notes.supporter_id") end - def tag_masters Qx.select("*").from(:tag_masters).where("nonprofit_id = $id AND NOT deleted", id: @id) end + + def tag_joins_through_supporters + Qx.select("tag_joins.id, tag_joins.supporter_id, tag_joins.tag_master_id") + .from(:tag_joins) + .join(:supporters, "supporters.id = tag_joins.supporter_id") + end end \ No newline at end of file diff --git a/app/legacy_lib/query_supporters.rb b/app/legacy_lib/query_supporters.rb index 11b4f4762..42bea053c 100644 --- a/app/legacy_lib/query_supporters.rb +++ b/app/legacy_lib/query_supporters.rb @@ -159,25 +159,18 @@ def self._full_search(np_id, query) # # return new_supporters # end - def self.undeleted_supporters(np_id) - - Qx.select('id') - .from(:supporters) - .where("supporters.nonprofit_id = $id and deleted != 'true'", id: np_id ) - end def self.tag_joins_only_for_nonprofit_query(np_id) Qx.select("tag_joins.id, tag_joins.supporter_id, tag_joins.tag_master_id") .from(:tag_joins) - .join(undeleted_supporters(np_id).as('tags_to_supporters'), "tags_to_supporters.id = tag_joins.supporter_id") + .join(:supporters, "supporters.id = tag_joins.supporter_id") end def self.build_tag_query(np_id) tags_query = Qx.select("tag_joins.supporter_id", "ARRAY_AGG(tag_masters.id) AS ids", "ARRAY_AGG(tag_masters.name::text) AS names") - .from(tag_joins_only_for_nonprofit_query(np_id).as(:tag_joins)) + .from(:tag_joins) .join(:tag_masters, "tag_masters.id=tag_joins.tag_master_id") - .where("tag_masters.nonprofit_id = $id AND NOT tag_masters.deleted ", id: np_id.to_i) .group_by("tag_joins.supporter_id") .as(:tags) end @@ -191,7 +184,6 @@ def self.full_filter_expr(np_id, query) .from(Qx.select('*').from(:payments).where("nonprofit_id = $id", id: np_id).as(:payments).parse) .join(Qx.select('id') .from(:supporters) - .where("supporters.nonprofit_id = $id and deleted != 'true'", id: np_id ) .as("payments_to_supporters"), "payments_to_supporters.id = payments.supporter_id" ) .as("outer_from_payment_to_supporter") @@ -214,6 +206,7 @@ def self.full_filter_expr(np_id, query) .with(:tag_masters, np_queries.tag_masters) .with(:supporters, np_queries.supporters) .with(:supporter_notes, np_queries.supporter_notes) + .with(:tag_joins, np_queries.tag_joins_through_supporters) .from(:supporters) .join('nonprofits', 'nonprofits.id=supporters.nonprofit_id') .left_join(