diff --git a/ghost/core/core/server/models/post.js b/ghost/core/core/server/models/post.js index 2a0c599e796..5838aa2e758 100644 --- a/ghost/core/core/server/models/post.js +++ b/ghost/core/core/server/models/post.js @@ -1399,7 +1399,7 @@ Post = ghostBookshelf.Model.extend({ modelOrCollection.query('columns', 'posts.*', (qb) => { qb.count('members_created_events.id') .from('members_created_events') - .whereRaw('posts.id = members_created_events.attribution_id') + .whereRaw('`posts`.id = members_created_events.attribution_id') .as('count__signups'); }); }, @@ -1407,7 +1407,7 @@ Post = ghostBookshelf.Model.extend({ modelOrCollection.query('columns', 'posts.*', (qb) => { qb.count('members_subscription_created_events.id') .from('members_subscription_created_events') - .whereRaw('posts.id = members_subscription_created_events.attribution_id') + .whereRaw('`posts`.id = members_subscription_created_events.attribution_id') .as('count__paid_conversions'); }); }, @@ -1419,15 +1419,14 @@ Post = ghostBookshelf.Model.extend({ qb.count('*') .from('k') .with('k', (q) => { - q.select('member_id') + q.select('member_id','attribution_id') .from('members_subscription_created_events') - .whereRaw('posts.id = members_subscription_created_events.attribution_id') .union(function () { - this.select('member_id') - .from('members_created_events') - .whereRaw('posts.id = members_created_events.attribution_id'); + this.select('member_id','attribution_id') + .from('members_created_events'); }); }) + .whereRaw('`k`.attribution_id = `posts`.id') .as('count__conversions'); }); }, @@ -1436,7 +1435,7 @@ Post = ghostBookshelf.Model.extend({ qb.countDistinct('members_click_events.member_id') .from('members_click_events') .join('redirects', 'members_click_events.redirect_id', 'redirects.id') - .whereRaw('posts.id = redirects.post_id') + .whereRaw('`posts`.id = redirects.post_id') .as('count__clicks'); }); }, @@ -1444,7 +1443,7 @@ Post = ghostBookshelf.Model.extend({ modelOrCollection.query('columns', 'posts.*', (qb) => { qb.select(qb.client.raw('COALESCE(ROUND(AVG(score) * 100), 0)')) .from('members_feedback') - .whereRaw('posts.id = members_feedback.post_id') + .whereRaw('`posts`.id = members_feedback.post_id') .as('count__sentiment'); }); }, @@ -1452,7 +1451,7 @@ Post = ghostBookshelf.Model.extend({ modelOrCollection.query('columns', 'posts.*', (qb) => { qb.count('*') .from('members_feedback') - .whereRaw('posts.id = members_feedback.post_id AND members_feedback.score = 0') + .whereRaw('`posts`.id = members_feedback.post_id AND members_feedback.score = 0') .as('count__negative_feedback'); }); }, @@ -1460,7 +1459,7 @@ Post = ghostBookshelf.Model.extend({ modelOrCollection.query('columns', 'posts.*', (qb) => { qb.sum('score') .from('members_feedback') - .whereRaw('posts.id = members_feedback.post_id') + .whereRaw('`posts`.id = members_feedback.post_id') .as('count__positive_feedback'); }); }