From 74fb2975843e243730edf4a71490c275581c4acb Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 20 Apr 2016 15:09:36 +0200 Subject: [PATCH] server/db: fix aggregates --- server/szurubooru/db/post.py | 6 +++--- server/szurubooru/db/tag.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/szurubooru/db/post.py b/server/szurubooru/db/post.py index 9717f2f..0f617f2 100644 --- a/server/szurubooru/db/post.py +++ b/server/szurubooru/db/post.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, DateTime, String, ForeignKey, table +from sqlalchemy import Column, Integer, DateTime, String, ForeignKey from sqlalchemy.orm import relationship, column_property from sqlalchemy.sql.expression import func, select from szurubooru.db.base import Base @@ -58,9 +58,9 @@ class Post(Base): secondaryjoin=post_id == PostRelation.child_id) tag_count = column_property( - select([func.count('1')]) + select([func.count(PostTag.tag_id)]) \ .where(PostTag.post_id == post_id) \ - .correlate(table('Post'))) + .correlate_except(PostTag)) # TODO: wire these fav_count = Column('auto_fav_count', Integer, nullable=False, default=0) diff --git a/server/szurubooru/db/tag.py b/server/szurubooru/db/tag.py index 55e1857..f54a03e 100644 --- a/server/szurubooru/db/tag.py +++ b/server/szurubooru/db/tag.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, DateTime, String, ForeignKey, table +from sqlalchemy import Column, Integer, DateTime, String, ForeignKey from sqlalchemy.orm import relationship, column_property from sqlalchemy.sql.expression import func, select from szurubooru.db.base import Base @@ -63,9 +63,9 @@ class Tag(Base): lazy='joined') post_count = column_property( - select([func.count('Post.post_id')]) \ + select([func.count(PostTag.post_id)]) \ .where(PostTag.tag_id == tag_id) \ - .correlate(table('Tag'))) + .correlate_except(PostTag)) first_name = column_property( select([TagName.name]) \