This commit is contained in:
Untone 2024-08-07 15:04:17 +03:00
parent c601fcc2a4
commit ec7b25df3c

View File

@ -39,17 +39,26 @@ def query_shouts():
select(
Shout.id.label("shout_id"),
func.json_agg(
distinct(
func.json_build_object(
'id', Author.id,
'name', Author.name,
'slug', Author.slug,
'pic', Author.pic
)
)
).label("authors")
)
.select_from(
select(
distinct(Author.id),
Author.name,
Author.slug,
Author.pic,
Shout.id.label("shout_id")
)
.join(ShoutAuthor, ShoutAuthor.author == Author.id)
.join(Shout, Shout.id == ShoutAuthor.shout)
.subquery()
)
.group_by(Shout.id)
.subquery()
)
@ -58,17 +67,26 @@ def query_shouts():
select(
Shout.id.label("shout_id"),
func.json_agg(
distinct(
func.json_build_object(
'id', Topic.id,
'title', Topic.title,
'body', Topic.body,
'slug', Topic.slug
)
)
).label("topics")
)
.select_from(
select(
distinct(Topic.id),
Topic.title,
Topic.body,
Topic.slug,
Shout.id.label("shout_id")
)
.join(ShoutTopic, ShoutTopic.topic == Topic.id)
.join(Shout, Shout.id == ShoutTopic.shout)
.subquery()
)
.group_by(Shout.id)
.subquery()
)