From 1aa7216601690f572b804b4ccd86b8b1e3ce3cc4 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 15 Jan 2025 01:24:44 +0100 Subject: [PATCH] fix: select correct columns with correct alias --- upub/routes/src/activitypub/object/likes.rs | 16 ++++++++++++++-- upub/routes/src/activitypub/object/shares.rs | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/upub/routes/src/activitypub/object/likes.rs b/upub/routes/src/activitypub/object/likes.rs index 50efc1c..86e5ecd 100644 --- a/upub/routes/src/activitypub/object/likes.rs +++ b/upub/routes/src/activitypub/object/likes.rs @@ -1,6 +1,6 @@ use apb::{BaseMut, CollectionMut, LD}; use axum::extract::{Path, Query, State}; -use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect, RelationTrait}; +use sea_orm::{ColumnTrait, EntityTrait, Iterable, QueryFilter, QueryOrder, QuerySelect, RelationTrait, SelectColumns, Iden, EntityName}; use upub::{selector::{RichActivity, RichFillable}, Context}; use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity}; @@ -38,7 +38,7 @@ pub async fn page( .ok_or_else(crate::ApiError::not_found)?; let (limit, offset) = page.pagination(); - let items = upub::model::like::Entity::find() + let mut select = upub::model::like::Entity::find() .distinct() .join(sea_orm::JoinType::InnerJoin, upub::model::like::Relation::Activities.def()) .join(sea_orm::JoinType::InnerJoin, upub::model::activity::Relation::Addressing.def()) @@ -47,6 +47,18 @@ pub async fn page( .order_by_desc(upub::model::like::Column::Published) .limit(limit) .offset(offset) + .select_only(); + + for col in upub::model::activity::Column::iter() { + select = select.select_column_as(col, format!("{}{}", upub::model::activity::Entity.table_name(), col.to_string())); + } + + select = select.select_column_as( + upub::model::addressing::Column::Published, + format!("{}{}", upub::model::addressing::Entity.table_name(), upub::model::addressing::Column::Published.to_string()) + ); + + let items = select .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/object/shares.rs b/upub/routes/src/activitypub/object/shares.rs index db65e4b..d56f6f5 100644 --- a/upub/routes/src/activitypub/object/shares.rs +++ b/upub/routes/src/activitypub/object/shares.rs @@ -1,6 +1,6 @@ use apb::{BaseMut, CollectionMut, LD}; use axum::extract::{Path, Query, State}; -use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect, RelationTrait}; +use sea_orm::{ColumnTrait, EntityName, EntityTrait, Iden, Iterable, QueryFilter, QueryOrder, QuerySelect, RelationTrait, SelectColumns}; use upub::{selector::{RichActivity, RichFillable}, Context}; use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity}; @@ -38,7 +38,7 @@ pub async fn page( .ok_or_else(crate::ApiError::not_found)?; let (limit, offset) = page.pagination(); - let items = upub::model::announce::Entity::find() + let mut select = upub::model::announce::Entity::find() .distinct() .join(sea_orm::JoinType::InnerJoin, upub::model::announce::Relation::Activities.def()) .join(sea_orm::JoinType::InnerJoin, upub::model::activity::Relation::Addressing.def()) @@ -47,6 +47,18 @@ pub async fn page( .order_by_desc(upub::model::announce::Column::Published) .limit(limit) .offset(offset) + .select_only(); + + for col in upub::model::activity::Column::iter() { + select = select.select_column_as(col, format!("{}{}", upub::model::activity::Entity.table_name(), col.to_string())); + } + + select = select.select_column_as( + upub::model::addressing::Column::Published, + format!("{}{}", upub::model::addressing::Entity.table_name(), upub::model::addressing::Column::Published.to_string()) + ); + + let items = select .into_model::() .all(ctx.db()) .await?