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]) \