Skip to content
Discussion options

You must be logged in to vote

I found the answer while testing this a bit more.

For this kind of case, find_also_related is probably not the best fit. It is nice for simple relation loading, but when the joined row needs its own custom condition, a manual LEFT JOIN gives much better control.

The important part is to put the condition for the joined table into the ON clause, not into WHERE.

If the condition is added to WHERE, the LEFT JOIN can behave like an INNER JOIN, because rows without a matching related record will be filtered out.

Example idea:

use sea_orm::{
    sea_query::Expr,
    ColumnTrait, EntityTrait, JoinType, QueryFilter, QuerySelect,
};

let query = food::Entity::find()
    .filter(food::Column::Source.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by For8stt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant