server/db: fix aggregates
This commit is contained in:
parent
a926838b90
commit
74fb297584
|
@ -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.orm import relationship, column_property
|
||||||
from sqlalchemy.sql.expression import func, select
|
from sqlalchemy.sql.expression import func, select
|
||||||
from szurubooru.db.base import Base
|
from szurubooru.db.base import Base
|
||||||
|
@ -58,9 +58,9 @@ class Post(Base):
|
||||||
secondaryjoin=post_id == PostRelation.child_id)
|
secondaryjoin=post_id == PostRelation.child_id)
|
||||||
|
|
||||||
tag_count = column_property(
|
tag_count = column_property(
|
||||||
select([func.count('1')])
|
select([func.count(PostTag.tag_id)]) \
|
||||||
.where(PostTag.post_id == post_id) \
|
.where(PostTag.post_id == post_id) \
|
||||||
.correlate(table('Post')))
|
.correlate_except(PostTag))
|
||||||
|
|
||||||
# TODO: wire these
|
# TODO: wire these
|
||||||
fav_count = Column('auto_fav_count', Integer, nullable=False, default=0)
|
fav_count = Column('auto_fav_count', Integer, nullable=False, default=0)
|
||||||
|
|
|
@ -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.orm import relationship, column_property
|
||||||
from sqlalchemy.sql.expression import func, select
|
from sqlalchemy.sql.expression import func, select
|
||||||
from szurubooru.db.base import Base
|
from szurubooru.db.base import Base
|
||||||
|
@ -63,9 +63,9 @@ class Tag(Base):
|
||||||
lazy='joined')
|
lazy='joined')
|
||||||
|
|
||||||
post_count = column_property(
|
post_count = column_property(
|
||||||
select([func.count('Post.post_id')]) \
|
select([func.count(PostTag.post_id)]) \
|
||||||
.where(PostTag.tag_id == tag_id) \
|
.where(PostTag.tag_id == tag_id) \
|
||||||
.correlate(table('Tag')))
|
.correlate_except(PostTag))
|
||||||
|
|
||||||
first_name = column_property(
|
first_name = column_property(
|
||||||
select([TagName.name]) \
|
select([TagName.name]) \
|
||||||
|
|
Loading…
Reference in New Issue