Pull out query for campaign and children
This commit is contained in:
parent
3494ec36f5
commit
c4f9176e2a
2 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue