pub trait ModelTrait:
Clone
+ Send
+ 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 as Linked>::ToEntity>
where L: Linked<FromEntity = Self::Entity> { ... }
fn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>
where 'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait { ... }
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§
Sourcetype Entity: EntityTrait
type Entity: EntityTrait
The EntityTrait this model belongs to.
Required Methods§
Sourcefn get_value_type(c: <Self::Entity as EntityTrait>::Column) -> ArrayType
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.
Provided Methods§
Sourcefn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value)
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.
Sourcefn find_linked<L>(&self, l: L) -> Select<<L as Linked>::ToEntity>
fn find_linked<L>(&self, l: L) -> Select<<L as Linked>::ToEntity>
Sourcefn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>where
'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait,
fn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>where
'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait,
Delete a model
Sourcefn get_primary_key_value(&self) -> ValueTuple
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".