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
This commit is contained in:
əlemi 2024-06-25 05:58:16 +02:00
parent ae4950b2e7
commit 4e9f6ea419
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

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