Skip to main content

ModelTrait

Trait ModelTrait 

Source
pub trait ModelTrait:
    Clone
    + Send
    + Sync
    + Debug {
    type Entity: EntityTrait<Model = Self>;

    // Required methods
    fn get(&self, column: <Self::Entity as EntityTrait>::Column) -> Value;
    fn set(
        &mut self,
        column: <Self::Entity as EntityTrait>::Column,
        value: Value,
    ) -> Result<()>;

    // Provided methods
    fn find_related<R>(&self, _: R) -> Select<R>
       where R: EntityTrait,
             Self::Entity: Related<R> { ... }
    fn find_linked<L>(&self, link: L) -> Select<L::ToEntity>
       where L: Linked<FromEntity = Self::Entity> { ... }
    fn delete<'life0, 'async_trait, C>(
        self,
        db: &'life0 C,
    ) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>>
       where C: ConnectionTrait + 'async_trait,
             Self: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel> + 'async_trait,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior,
             'life0: 'async_trait { ... }
}
Expand description

A row of an entity as a plain struct, derived by DeriveEntityModel.

Required Associated Types§

Source

type Entity: EntityTrait<Model = Self>

The entity this model belongs to.

Required Methods§

Source

fn get(&self, column: <Self::Entity as EntityTrait>::Column) -> Value

Reads a column as a SQL value.

Source

fn set( &mut self, column: <Self::Entity as EntityTrait>::Column, value: Value, ) -> Result<()>

Writes a column from a SQL value.

§Errors

Returns DbErr::Type when the value cannot be decoded as the field type.

Provided Methods§

Builds a query for the rows of R related to this model, following the junction table of a many-to-many relation when there is one.

Source

fn find_linked<L>(&self, link: L) -> Select<L::ToEntity>
where L: Linked<FromEntity = Self::Entity>,

Builds a query for the rows reached from this model through the chain link.

Source

fn delete<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait, Self: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel> + 'async_trait, <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior, 'life0: 'async_trait,

Deletes the row this model was read from, running the active model’s ActiveModelBehavior hooks.

§Errors

Returns the errors of ActiveModelTrait::delete.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§