You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone, thanks for this wonderful library!
I have two HUGE questions:
1.Using .find_with_related.... How am I supposed to filter the related model? I mean like “Find related only if condition X is met, else None”, here's my example:
#[derive(Copy,Clone,Debug,EnumIter,DeriveRelation)]pubenumRelation{#[sea_orm( belongs_to = "Entity", from = "Column::Overrides", to = "Column::Id", on_update = "NoAction", on_delete = "SetNull")]SelfRef,}implRelated<Entity>forEntity{fnto() -> RelationDef{Relation::SelfRef.def()}}let(food, food_override) = foods::Entity::find_by_id(food_id).filter(foods::Column::Source.ne(Sources::User)).find_also_related(foods::Entity)// Here, I would like to do something like .filter(related_entity.owned_by.eq(user_id)).one(&self.database.clone()).await?
.ok_or_else(|| ServiceError::FoodServiceError::FoodNotFound))?
I can't understand how i can get, in a query with .limit and .skip, the total count (without taking into account the limit and skip) without doing two queries that are really slow. Here's what i am currently using, which is obviously super slow:
let query = foods::Entity::find().filter(SomeEnormousAndSlowFilter)let foods_count = query.clone().count(&self.database.clone()).await?;let foods = query.limit(100).skip(100).find_also_related(foods::Entity)// something like .filter(related_entity.owned_by.eq(user_id)).all(&self.database.clone()).await?
.into_iter().map(|(food, food_override)| FoodWithOverride{
food,
food_override,});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone, thanks for this wonderful library!
I have two HUGE questions:
1.Using .find_with_related.... How am I supposed to filter the related model? I mean like “Find related only if condition X is met, else None”, here's my example:
Beta Was this translation helpful? Give feedback.
All reactions