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:
parent
ae4950b2e7
commit
4e9f6ea419
1 changed files with 10 additions and 1 deletions
|
@ -86,11 +86,20 @@ impl Query {
|
||||||
condition = condition.add(model::relation::Column::Accept.is_not_null());
|
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()
|
let mut select = model::relation::Entity::find()
|
||||||
.join(
|
.join(
|
||||||
sea_orm::JoinType::InnerJoin,
|
sea_orm::JoinType::InnerJoin,
|
||||||
model::relation::Entity::belongs_to(model::actor::Entity)
|
model::relation::Entity::belongs_to(model::actor::Entity)
|
||||||
.from(model::relation::Column::Follower)
|
.from(direction)
|
||||||
.to(model::actor::Column::Internal)
|
.to(model::actor::Column::Internal)
|
||||||
.into()
|
.into()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue