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"], ["donations", "donations.campaign_id=campaigns.id"],
["payments", "payments.donation_id=donations.id"] ["payments", "payments.donation_id=donations.id"]
) )
.where("campaigns.id IN (#{Qx.select("id").from('campaigns') .where("campaigns.id IN (#{QueryCampaigns
.where("campaigns.id = $id OR campaigns.parent_campaign_id=$id", id: campaign_id).parse .get_campaign_and_children(campaign_id)
.parse
})") })")
.execute .execute
.last .last

View file

@ -73,5 +73,12 @@ module QueryCampaigns
) )
end 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 end