From d3262accc5266895c8408dca94628979443e773f Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 9 Apr 2024 19:48:02 +0300 Subject: [PATCH] shout-topic-comments --- resolvers/stat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resolvers/stat.py b/resolvers/stat.py index a49334e3..a1606b64 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -41,8 +41,8 @@ def add_topic_stat_columns(q): Shout.id.label('shout_id'), func.coalesce(func.count(Reaction.id)).label('comments_count') ) - .join(ShoutTopic, Topic.id == ShoutTopic.topic) - .join(Shout, ShoutTopic.shout == Shout.id) + .join(ShoutTopic, ShoutTopic.shout == Shout.id) + .join(Topic, ShoutTopic.topic == Topic.id) .outerjoin( Reaction, and_( @@ -55,6 +55,7 @@ def add_topic_stat_columns(q): .subquery() ) + q = q.outerjoin(sub_comments, aliased_shout_topic.shout == sub_comments.c.shout_id) q = q.add_columns(func.coalesce(sub_comments.c.comments_count, 0).label('comments_stat'))