I am a beginner here using sea-orm. I am trying to break down query for filtering my data. params are input from http query parameters. Based on value of params i want to filter data.
let test = ProductEntity::find();
if params.get("price_gt").is_some() {
test.filter(product_entity::Column::Price.eq(20));
}
dbg!(test.all(&db).await?);
Help meIssue
It is a little late, but it can be useful for others.
Entity
uses the Build pattern. As you can see here filter takesmut self
as argument but also returnsself
.In this specific case, we have to make test mutable:
let mut test = ...
, and in the if statement, we have to return ownership to the test variable:test = test.filter(product_entity::Column::Price.eq(20));
Then it should work as expected.