pub struct RelationBuilder<E>{ /* private fields */ }Expand description
Builder for loading relationships on entities
This builder provides a fluent API for loading relationships with automatic batching to prevent N+1 queries.
§Example
use ormkit::relations::{RelationBuilder, BelongsTo, Loaded};
// Load users for posts
let posts_with_users = RelationBuilder::for_entities(posts)
.load::<User>(&pool)
.await?;
for post_with_user in posts_with_users {
let post = post_with_user.entity();
let user = post_with_user.relation();
println!("Post: {:?}, User: {:?}", post, user);
}Implementations§
Source§impl<E> RelationBuilder<E>
impl<E> RelationBuilder<E>
Sourcepub fn for_entities(entities: Vec<E>) -> Self
pub fn for_entities(entities: Vec<E>) -> Self
Create a new RelationBuilder for the given entities
§Arguments
entities- The entities to load relationships for
Sourcepub fn with_strategy(self, strategy: LoadStrategy) -> Self
pub fn with_strategy(self, strategy: LoadStrategy) -> Self
Sourcepub async fn load_belongs_to<P>(
self,
pool: &PgPool,
) -> Result<Vec<Loaded<E, Option<P>>>, LoadError>
pub async fn load_belongs_to<P>( self, pool: &PgPool, ) -> Result<Vec<Loaded<E, Option<P>>>, LoadError>
Sourcepub async fn load_has_many<C>(
self,
pool: &PgPool,
) -> Result<Vec<Loaded<E, HasManyLoaded<C>>>, LoadError>
pub async fn load_has_many<C>( self, pool: &PgPool, ) -> Result<Vec<Loaded<E, HasManyLoaded<C>>>, LoadError>
Auto Trait Implementations§
impl<E> Freeze for RelationBuilder<E>
impl<E> RefUnwindSafe for RelationBuilder<E>where
E: RefUnwindSafe,
impl<E> Send for RelationBuilder<E>
impl<E> Sync for RelationBuilder<E>
impl<E> Unpin for RelationBuilder<E>where
E: Unpin,
impl<E> UnsafeUnpin for RelationBuilder<E>
impl<E> UnwindSafe for RelationBuilder<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more