pub struct WithRelated<M> {
pub inner: M,
/* private fields */
}Expand description
A model instance with an attached relation cache (level-1, in-process).
Derefs to the inner model so field access (post.title) works directly.
Relations are populated by QueryBuilder::all() when .select_related()
or .prefetch_related() were chained before execution.
§Example
ⓘ
let posts = Post::filter(&pool)
.select_related(Post::AUTHOR_ID)
.prefetch_related(Comment::POST_ID)
.all()
.await?;
for post in &posts {
println!("{} by {}", post.title, post.related::<Author>().name);
for comment in post.prefetched::<Comment>() {
println!(" - {}", comment.body);
}
}Fields§
§inner: MImplementations§
Source§impl<M> WithRelated<M>
impl<M> WithRelated<M>
Sourcepub fn into_inner(self) -> M
pub fn into_inner(self) -> M
The model, dropping the loaded relations.
Returns the FK-related instance loaded by select_related.
§Panics
Panics with a clear message if .select_related(..) was not called for R
on the query builder.
Trait Implementations§
Source§impl<M> Deref for WithRelated<M>
impl<M> Deref for WithRelated<M>
Auto Trait Implementations§
impl<M> !RefUnwindSafe for WithRelated<M>
impl<M> !UnwindSafe for WithRelated<M>
impl<M> Forget for WithRelated<M>
impl<M> Freeze for WithRelated<M>where
M: Freeze,
impl<M> Send for WithRelated<M>where
M: Send,
impl<M> Sync for WithRelated<M>where
M: Sync,
impl<M> Unpin for WithRelated<M>where
M: Unpin,
impl<M> UnsafeUnpin for WithRelated<M>where
M: UnsafeUnpin,
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