From b078c0006c4dbd02a9a301df147f807396d93f15 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Tue, 23 Apr 2019 22:36:20 +0530 Subject: [PATCH] Fix missing lists fetch in query-campaigns --- frontend/my/src/Campaign.js | 2 -- queries.sql | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/my/src/Campaign.js b/frontend/my/src/Campaign.js index ba69d39..88c46f5 100644 --- a/frontend/my/src/Campaign.js +++ b/frontend/my/src/Campaign.js @@ -387,8 +387,6 @@ class TheFormDef extends React.PureComponent { } } - console.log(subLists) - if (this.record) { this.props.pageTitle(record.name + " / Campaigns") } else { diff --git a/queries.sql b/queries.sql index 14a0a6b..ebe3d5a 100644 --- a/queries.sql +++ b/queries.sql @@ -274,7 +274,13 @@ INSERT INTO campaign_lists (campaign_id, list_id, list_name) -- there's a COUNT() OVER() that still returns the total result count -- for pagination in the frontend, albeit being a field that'll repeat -- with every resultant row. -SELECT COUNT(*) OVER () AS total, campaigns.* +SELECT COUNT(*) OVER () AS total, campaigns.*, ( + SELECT COALESCE(ARRAY_TO_JSON(ARRAY_AGG(l)), '[]') FROM ( + SELECT COALESCE(campaign_lists.list_id, 0) AS id, + campaign_lists.list_name AS name + FROM campaign_lists WHERE campaign_lists.campaign_id = campaigns.id + ) l + ) AS lists FROM campaigns WHERE ($1 = 0 OR id = $1) AND status=ANY(CASE WHEN ARRAY_LENGTH($2::campaign_status[], 1) != 0 THEN $2::campaign_status[] ELSE ARRAY[status] END)