Skip to main content

ManyToManyManager

Struct ManyToManyManager 

Source
pub struct ManyToManyManager<S: Model, T: Model> { /* private fields */ }
Expand description

Accessor for one many-to-many relation of one source object (post.tags(&db)). Generated accessors construct it; its query and mutation methods (all, add, remove, clear, set) run on db.

Implementations§

Source§

impl<S: Model, T: Model> ManyToManyManager<S, T>

Source

pub fn queryset(&self) -> QuerySet<T>

Lazy queryset over the related objects (WHERE pk IN (SELECT target FROM through WHERE source = ..)); filter or order it further.

Source

pub async fn all(&self) -> Result<Vec<T>, OrmError>

Every related object.

§Errors

Capability or backend errors.

Source

pub async fn count(&self) -> Result<u64, OrmError>

Number of related objects.

§Errors

Capability or backend errors.

Source

pub async fn contains(&self, object: &T) -> Result<bool, OrmError>

Whether object is related.

§Errors

Capability or backend errors.

Source

pub async fn add<'a>( &self, objects: impl IntoIterator<Item = &'a T>, ) -> Result<(), OrmError>

Relate objects (already related ones are skipped).

§Errors

Capability or backend errors (BackendError::Constraint when a target does not exist).

Source

pub async fn add_pks( &self, keys: impl IntoIterator<Item = T::Pk>, ) -> Result<(), OrmError>

add by primary key.

§Errors

As add.

Source

pub async fn remove<'a>( &self, objects: impl IntoIterator<Item = &'a T>, ) -> Result<u64, OrmError>

Unrelate objects; returns the number of links removed.

§Errors

Capability or backend errors.

Source

pub async fn remove_pks( &self, keys: impl IntoIterator<Item = T::Pk>, ) -> Result<u64, OrmError>

remove by primary key.

§Errors

As remove.

Source

pub async fn clear(&self) -> Result<u64, OrmError>

Unrelate everything; returns the number of links removed.

§Errors

Capability or backend errors.

Source

pub async fn set<'a>( &self, objects: impl IntoIterator<Item = &'a T>, ) -> Result<(), OrmError>

Make objects exactly the related set: add the missing, remove the rest.

§Errors

Capability or backend errors; nothing changes on failure.

Source

pub async fn set_pks( &self, keys: impl IntoIterator<Item = T::Pk>, ) -> Result<(), OrmError>

set by primary key.

§Errors

As set.

Source§

impl<S: Model, T: Model> ManyToManyManager<S, T>

Source

pub fn new(db: &Db, meta: &'static ManyToManyMeta, source_pk: Value) -> Self

Manager for relation meta of the object whose key is source_pk.

Source

pub fn db(&self) -> &Db

Database handle.

Source

pub fn meta(&self) -> &'static ManyToManyMeta

Relation metadata.

Source

pub fn source_pk(&self) -> &Value

Key of the source object.

Auto Trait Implementations§

§

impl<S, T> !RefUnwindSafe for ManyToManyManager<S, T>

§

impl<S, T> !UnwindSafe for ManyToManyManager<S, T>

§

impl<S, T> Freeze for ManyToManyManager<S, T>

§

impl<S, T> Send for ManyToManyManager<S, T>

§

impl<S, T> Sync for ManyToManyManager<S, T>

§

impl<S, T> Unpin for ManyToManyManager<S, T>

§

impl<S, T> UnsafeUnpin for ManyToManyManager<S, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more