From 4e9f6ea419926702c5798734f4feac2f524dbfac Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 25 Jun 2024 05:58:16 +0200 Subject: [PATCH] fix: "smart" join direction on related query not really smart because if both are some it arbitrarily returns "to" actor but ehhhh i mean if you have both "from" and "to" you're probably just checking that it exists so who cares which comes back --- upub/core/src/selector/query.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/upub/core/src/selector/query.rs b/upub/core/src/selector/query.rs index 1d8ccff..d0d3707 100644 --- a/upub/core/src/selector/query.rs +++ b/upub/core/src/selector/query.rs @@ -86,11 +86,20 @@ impl Query { condition = condition.add(model::relation::Column::Accept.is_not_null()); } + let direction = match (from, to) { + // TODO its super arbitrary to pick "Following" as default direction!!! + (Some(_), Some(_)) => model::relation::Column::Following, + (None, None) => model::relation::Column::Following, + // TODO i should really probably change this function's api, maybe add another param?? + (Some(_), None) => model::relation::Column::Following, + (None, Some(_)) => model::relation::Column::Follower, + }; + let mut select = model::relation::Entity::find() .join( sea_orm::JoinType::InnerJoin, model::relation::Entity::belongs_to(model::actor::Entity) - .from(model::relation::Column::Follower) + .from(direction) .to(model::actor::Column::Internal) .into() )