pub struct ThenLoad<P: View, C: View, K> { /* private fields */ }Expand description
One level of a load path: fetch C for a set of P, keyed, batched and
deduplicated — plus the levels hanging off it.
Generated then_load::…() functions return one of these. It is a
Mod over the parent’s ModelSelect, so it drops into a query tuple
like any other mod; then is what makes it a path
rather than a single level.
The three function pointers are the model-specific half — which keys to
take off the parents, how to filter the child query by them, how to
attach the results — and they are function pointers rather than closures
because generated code has nothing to capture, which keeps this type
Send + Sync without a bound in sight.
Implementations§
Source§impl<P, C, K> ThenLoad<P, C, K>
impl<P, C, K> ThenLoad<P, C, K>
Sourcepub fn new(
keys: fn(&[P::Row]) -> Vec<K>,
key_filter: fn(Vec<K>, &mut ModelSelect<C>),
attach: fn(&mut [P::Row], Vec<C::Row>),
) -> Self
pub fn new( keys: fn(&[P::Row]) -> Vec<K>, key_filter: fn(Vec<K>, &mut ModelSelect<C>), attach: fn(&mut [P::Row], Vec<C::Row>), ) -> Self
Assemble a level. Generated code calls this; the three arguments are the parent keys, the child-query filter and the attachment.
Sourcepub fn then(self, deeper: impl IntoLoader<C::Row>) -> Self
pub fn then(self, deeper: impl IntoLoader<C::Row>) -> Self
Hang another level off this one: load deeper over the children this
level fetched, before they are attached to their parents.
Typed by the child model — only a loader over C::Row fits — so the
path is checked at the call site rather than spelled in a string.
Sourcepub fn with(
self,
shape: impl Fn(&mut ModelSelect<C>) + Send + Sync + 'static,
) -> Self
pub fn with( self, shape: impl Fn(&mut ModelSelect<C>) + Send + Sync + 'static, ) -> Self
Shape this level’s query: the closure runs on every batch query, after the key filter.
A closure rather than a mod because a mod is consumed when it is
applied and there may be many batches — and because a query is
re-issued every time the parent query runs. Anything that applies to a
ModelSelect goes in it: a filter, an order, a Layer 1 mod, or a
preload of the child’s own to-one relation.
posts::then_load::user()
.with(|q| users::is_active().eq(true).apply(q))