pub struct HasMany<P, C> { /* private fields */ }Expand description
One parent, many children.
ⓘ
// A user has many posts, found by `posts.user_id`.
HasMany::<User, Post>::new()Implementations§
Source§impl<P: Model, C: Model> HasMany<P, C>
impl<P: Model, C: Model> HasMany<P, C>
Sourcepub fn foreign_key(self, column: impl Into<String>) -> Self
pub fn foreign_key(self, column: impl Into<String>) -> Self
The column on the child pointing back at the parent.
Sourcepub fn local_key(self, column: impl Into<String>) -> Self
pub fn local_key(self, column: impl Into<String>) -> Self
The column on the parent the child points at. Defaults to its key.
Sourcepub fn matching(self, criteria: Criteria) -> Self
pub fn matching(self, criteria: Criteria) -> Self
Narrow, order or limit the children — a constrained eager load.
A limit here limits the whole query, not each parent’s share: one
query cannot take the newest three per parent without a window function,
and pretending otherwise would silently drop rows.
Trait Implementations§
Source§impl<P: Model, C: Model> Relation<P> for HasMany<P, C>
impl<P: Model, C: Model> Relation<P> for HasMany<P, C>
Source§fn far_key(&self) -> &str
fn far_key(&self) -> &str
The column on the other side that this relationship matches against.
Source§fn load<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
parents: &'life1 [P],
related: &'life2 dyn Repository<C>,
) -> Pin<Box<dyn Future<Output = Result<Related<C>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn load<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
parents: &'life1 [P],
related: &'life2 dyn Repository<C>,
) -> Pin<Box<dyn Future<Output = Result<Related<C>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Load the related rows for every parent, in one query.
Source§fn count<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
parents: &'life1 [P],
related: &'life2 dyn Repository<C>,
) -> Pin<Box<dyn Future<Output = Result<RelatedCounts>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn count<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
parents: &'life1 [P],
related: &'life2 dyn Repository<C>,
) -> Pin<Box<dyn Future<Output = Result<RelatedCounts>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Count the related rows for every parent, in one query, without
transferring them.
Source§fn for_one<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
parent: &'life1 P,
related: &'life2 dyn Repository<Self::Related>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Related>>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn for_one<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
parent: &'life1 P,
related: &'life2 dyn Repository<Self::Related>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Related>>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Load for a single parent. Read more
Auto Trait Implementations§
impl<P, C> Freeze for HasMany<P, C>
impl<P, C> RefUnwindSafe for HasMany<P, C>
impl<P, C> Send for HasMany<P, C>
impl<P, C> Sync for HasMany<P, C>
impl<P, C> Unpin for HasMany<P, C>
impl<P, C> UnsafeUnpin for HasMany<P, C>
impl<P, C> UnwindSafe for HasMany<P, C>
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> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
A human-readable name, used by wildcard listeners and log output.
Always the Rust type path; see the trait docs.