pub struct Relation<P> { /* private fields */ }Expand description
One relation of a parent resource’s records.
Declared by ResourceDef::relation; the related resource
must be registered on the same panel, which keys the relation by its slug:
let def: ResourceDef<PostResource> =
ResourceDef::new().relation(Relation::has_many::<CommentResource>(Comment::fields().post_id()));Implementations§
Source§impl<P> Relation<P>
impl<P> Relation<P>
Sourcepub fn has_many<C>(
foreign_key: Path<C::Model, impl ForeignKey<P::PrimaryKey>>,
) -> Selfwhere
C: Resource,
pub fn has_many<C>(
foreign_key: Path<C::Model, impl ForeignKey<P::PrimaryKey>>,
) -> Selfwhere
C: Resource,
Declare a has_many child resource whose foreign_key holds the owner’s primary key, a
single column.
let comments: Relation<Post> = Relation::has_many::<CommentResource>(Comment::fields().post_id());Sourcepub fn belongs_to_many<C>(via: impl Into<Path<P, List<C::Model>>>) -> Self
pub fn belongs_to_many<C>(via: impl Into<Path<P, List<C::Model>>>) -> Self
Declare a many-to-many child resource whose records the owner links through via, its
#[has_many(via = joins.target)] field: the owner’s linked records, which the table
attaches and detaches as join rows.
let tags: Relation<Post> = Relation::belongs_to_many::<TagResource>(Post::fields().tags());Attaching and detaching ask the owner’s policy for Update, as editing it does, and the
related resource’s for View on each record; mounting refuses a join model a link cannot
write.
Trait Implementations§
Auto Trait Implementations§
impl<P> !RefUnwindSafe for Relation<P>
impl<P> !UnwindSafe for Relation<P>
impl<P> Freeze for Relation<P>
impl<P> Send for Relation<P>
impl<P> Sync for Relation<P>
impl<P> Unpin for Relation<P>
impl<P> UnsafeUnpin for Relation<P>where
RelationKind<P>: UnsafeUnpin,
Arc<dyn Fn(&P) -> (Expr<bool>, String) + Send + Sync>: 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