Pull out query for campaign and children

This commit is contained in:
Eric Schultz 2018-11-20 13:04:17 -06:00
parent 3494ec36f5
commit c4f9176e2a
2 changed files with 10 additions and 2 deletions

View file

@ -13,8 +13,9 @@ module QueryCampaignMetrics
["donations", "donations.campaign_id=campaigns.id"],
["payments", "payments.donation_id=donations.id"]
)
.where("campaigns.id IN (#{Qx.select("id").from('campaigns')
.where("campaigns.id = $id OR campaigns.parent_campaign_id=$id", id: campaign_id).parse
.where("campaigns.id IN (#{QueryCampaigns
.get_campaign_and_children(campaign_id)
.parse
})")
.execute
.last

View file

@ -73,5 +73,12 @@ module QueryCampaigns
)
end
def self.get_campaign_and_children(campaign_id)
Qx.select("id")
.from('campaigns')
.where("campaigns.id = $id OR campaigns.parent_campaign_id=$id",
id: campaign_id)
end
end