add_author_stat-fix-2
This commit is contained in:
parent
9f881c0641
commit
b82a4bb2fa
|
@ -72,14 +72,17 @@ def add_author_stat_columns(q):
|
||||||
|
|
||||||
# Create a subquery for comments count
|
# Create a subquery for comments count
|
||||||
sub_comments = (
|
sub_comments = (
|
||||||
select(Author.id, func.count(Reaction.id).label('comments_stat'))
|
select(
|
||||||
.join(
|
Author.id,
|
||||||
|
func.coalesce(func.count(Reaction.id), 0).label('comments_stat')
|
||||||
|
)
|
||||||
|
.outerjoin(
|
||||||
Reaction,
|
Reaction,
|
||||||
and_(
|
and_(
|
||||||
Reaction.created_by == Author.id,
|
Reaction.created_by == Author.id,
|
||||||
Reaction.kind == ReactionKind.COMMENT.value,
|
Reaction.kind == ReactionKind.COMMENT.value,
|
||||||
Reaction.deleted_at.is_(None),
|
Reaction.deleted_at.is_(None),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.group_by(Author.id)
|
.group_by(Author.id)
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user