server/db: fix aggregates

This commit is contained in:
rr- 2016-04-20 15:09:36 +02:00
parent a926838b90
commit 74fb297584
2 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

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