pub trait LoaderTrait {
type Model: ModelTrait;
// Required methods
fn load_self<'life0, 'life1, 'async_trait, S, C>(
&'life0 self,
stmt: S,
relation_enum: <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation: Send,
S: EntityOrSelect<<<Self as LoaderTrait>::Model as ModelTrait>::Entity> + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_self_many<'life0, 'life1, 'async_trait, S, C>(
&'life0 self,
stmt: S,
relation_enum: <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation: Send,
S: EntityOrSelect<<<Self as LoaderTrait>::Model as ModelTrait>::Entity> + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_self_via<'life0, 'life1, 'async_trait, V, C>(
&'life0 self,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
V: EntityTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: RelatedSelfVia<V>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_self_via_rev<'life0, 'life1, 'async_trait, V, C>(
&'life0 self,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
V: EntityTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: RelatedSelfVia<V>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_one<'life0, 'life1, 'async_trait, R, S, C>(
&'life0 self,
stmt: S,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<R::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_many<'life0, 'life1, 'async_trait, R, S, C>(
&'life0 self,
stmt: S,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<R::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_many_to_many<'life0, 'life1, 'async_trait, R, S, V, C>(
&'life0 self,
stmt: S,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<R::Model>>, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
V: EntityTrait + 'async_trait,
V::Model: Send + Sync,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Batch-load related entities for a slice of parent models, avoiding the N+1 query problem.
Given a Vec<Parent>, load_one /
load_many / load_many_to_many
issue a single WHERE … IN (…) query for each relation hop and
reassemble the results, grouped per parent.
Required Associated Types§
Sourcetype Model: ModelTrait
type Model: ModelTrait
Source model
Required Methods§
Sourcefn load_self<'life0, 'life1, 'async_trait, S, C>(
&'life0 self,
stmt: S,
relation_enum: <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation: Send,
S: EntityOrSelect<<<Self as LoaderTrait>::Model as ModelTrait>::Entity> + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_self<'life0, 'life1, 'async_trait, S, C>(
&'life0 self,
stmt: S,
relation_enum: <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation: Send,
S: EntityOrSelect<<<Self as LoaderTrait>::Model as ModelTrait>::Entity> + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load self_ref relations
Sourcefn load_self_many<'life0, 'life1, 'async_trait, S, C>(
&'life0 self,
stmt: S,
relation_enum: <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation: Send,
S: EntityOrSelect<<<Self as LoaderTrait>::Model as ModelTrait>::Entity> + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_self_many<'life0, 'life1, 'async_trait, S, C>(
&'life0 self,
stmt: S,
relation_enum: <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Relation: Send,
S: EntityOrSelect<<<Self as LoaderTrait>::Model as ModelTrait>::Entity> + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load self_ref relations in reverse, output is Vec<Model> instead of
Option<Model> of load_self.
Sourcefn load_self_via<'life0, 'life1, 'async_trait, V, C>(
&'life0 self,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
V: EntityTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: RelatedSelfVia<V>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_self_via<'life0, 'life1, 'async_trait, V, C>(
&'life0 self,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
V: EntityTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: RelatedSelfVia<V>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load self_ref + via relations
Sourcefn load_self_via_rev<'life0, 'life1, 'async_trait, V, C>(
&'life0 self,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
V: EntityTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: RelatedSelfVia<V>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_self_via_rev<'life0, 'life1, 'async_trait, V, C>(
&'life0 self,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
V: EntityTrait + 'async_trait,
<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Model: Send + Sync,
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: RelatedSelfVia<V>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load self_ref + via relations, but in reverse
Sourcefn load_one<'life0, 'life1, 'async_trait, R, S, C>(
&'life0 self,
stmt: S,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<R::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_one<'life0, 'life1, 'async_trait, R, S, C>(
&'life0 self,
stmt: S,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<R::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load has_one relations
Sourcefn load_many<'life0, 'life1, 'async_trait, R, S, C>(
&'life0 self,
stmt: S,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<R::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_many<'life0, 'life1, 'async_trait, R, S, C>(
&'life0 self,
stmt: S,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<R::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load has_many relations
Sourcefn load_many_to_many<'life0, 'life1, 'async_trait, R, S, V, C>(
&'life0 self,
stmt: S,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<R::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
V: EntityTrait + 'async_trait,
V::Model: Send + Sync,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_many_to_many<'life0, 'life1, 'async_trait, R, S, V, C>(
&'life0 self,
stmt: S,
via: V,
db: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<R::Model>>, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
R: EntityTrait + 'async_trait,
R::Model: Send + Sync,
S: EntityOrSelect<R> + 'async_trait,
V: EntityTrait + 'async_trait,
V::Model: Send + Sync,
<Self::Model as ModelTrait>::Entity: Related<R>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Used to eager load many_to_many relations. In SeaORM 2.0 load_many already support M-N
relations so this method is not needed, only kept as legacy.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".