Skip to main content

ModelTrait

Trait ModelTrait 

Source
pub trait ModelTrait: Clone + Debug {
    type Entity: EntityTrait;

    // Required methods
    fn get(&self, c: <Self::Entity as EntityTrait>::Column) -> Value;
    fn get_value_type(c: <Self::Entity as EntityTrait>::Column) -> ArrayType;
    fn try_set(
        &mut self,
        c: <Self::Entity as EntityTrait>::Column,
        v: Value,
    ) -> Result<(), DbErr>;

    // Provided methods
    fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value) { ... }
    fn find_related<R>(&self, _: R) -> Select<R>
       where R: EntityTrait,
             Self::Entity: Related<R> { ... }
    fn find_linked<L>(&self, l: L) -> Select<L::ToEntity>
       where L: Linked<FromEntity = Self::Entity> { ... }
    fn delete<'a, A, C>(self, db: &'a C) -> Result<DeleteResult, DbErr>
       where Self: IntoActiveModel<A>,
             C: ConnectionTrait,
             A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + 'a { ... }
    fn get_primary_key_value(&self) -> ValueTuple { ... }
}
Expand description

The interface implemented by every Model — an instance of an EntityTrait, roughly an OOP “object” whose fields are the table’s columns.

Implemented automatically by #[derive(DeriveEntityModel)] / #[derive(DeriveModel)]. Pairs with an ActiveModelTrait type for mutations.

Required Associated Types§

Source

type Entity: EntityTrait

The EntityTrait this model belongs to.

Required Methods§

Source

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

Read the value of one column.

Source

fn get_value_type(c: <Self::Entity as EntityTrait>::Column) -> ArrayType

Type of the value stored by a column, used by reflection helpers such as Arrow conversion.

Source

fn try_set( &mut self, c: <Self::Entity as EntityTrait>::Column, v: Value, ) -> Result<(), DbErr>

Write a value to one column, returning an error if the value’s type does not match the column.

Provided Methods§

Source

fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value)

Write a value to one column. Panics if the value’s type doesn’t match the column; prefer try_set when the value comes from untrusted input.

Build a Select for models related to self via the Self::Entity: Related<R> relation. Use it together with .one(db) / .all(db) to fetch the related rows.

Source

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

Build a Select that follows a multi-hop link out of self. The hops are described by a Linked implementation.

Source

fn delete<'a, A, C>(self, db: &'a C) -> Result<DeleteResult, DbErr>
where Self: IntoActiveModel<A>, C: ConnectionTrait, A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + 'a,

Delete a model

Source

fn get_primary_key_value(&self) -> ValueTuple

Get the primary key value of the Model

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl ModelTrait for sea_orm::rbac::entity::permission::Model

Available on crate feature rbac only.
Source§

impl ModelTrait for sea_orm::rbac::entity::resource::Model

Available on crate feature rbac only.
Source§

impl ModelTrait for sea_orm::rbac::entity::role::Model

Available on crate feature rbac only.
Source§

impl ModelTrait for sea_orm::rbac::entity::role_hierarchy::Model

Available on crate feature rbac only.
Source§

impl ModelTrait for sea_orm::rbac::entity::role_permission::Model

Available on crate feature rbac only.
Source§

impl ModelTrait for sea_orm::rbac::entity::user_override::Model

Available on crate feature rbac only.
Source§

impl ModelTrait for sea_orm::rbac::entity::user_role::Model

Available on crate feature rbac only.