pub trait ActiveModelBehavior: ActiveModelTrait {
// Provided methods
fn new() -> Self { ... }
fn before_save<'life0, 'async_trait, C>(
self,
db: &'life0 C,
insert: bool,
) -> Pin<Box<dyn Future<Output = Result<Self, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn after_save<'life0, 'async_trait, C>(
model: <Self::Entity as EntityTrait>::Model,
db: &'life0 C,
insert: bool,
) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn before_delete<'life0, 'async_trait, C>(
self,
db: &'life0 C,
) -> Pin<Box<dyn Future<Output = Result<Self, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn after_delete<'life0, 'async_trait, C>(
self,
db: &'life0 C,
) -> Pin<Box<dyn Future<Output = Result<Self, DbErr>> + Send + 'async_trait>>
where C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}Expand description
A Trait for overriding the ActiveModel behavior
§Example
ⓘ
use sea_orm::entity::prelude::*;
// Use [DeriveEntity] to derive the EntityTrait automatically
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
/// The [EntityName] describes the name of a table
impl EntityName for Entity {
fn table_name(&self) -> &'static str {
"cake"
}
}
// Derive the ActiveModel
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model {
pub id: i32,
pub name: String,
}
impl ActiveModelBehavior for ActiveModel {}See module level docs crate::entity for a full example
Provided Methods§
Sourcefn new() -> Self
fn new() -> Self
Create a new ActiveModel with default values. This is also called by Default::default().
You can override it like the following:
ⓘ
fn new() -> Self {
Self {
status: Set(Status::New),
..ActiveModelTrait::default()
}
}Sourcefn before_save<'life0, 'async_trait, C>(
self,
db: &'life0 C,
insert: bool,
) -> Pin<Box<dyn Future<Output = Result<Self, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
fn before_save<'life0, 'async_trait, C>(
self,
db: &'life0 C,
insert: bool,
) -> Pin<Box<dyn Future<Output = Result<Self, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
Will be called before ActiveModel::insert, ActiveModel::update, and ActiveModel::save
Sourcefn after_save<'life0, 'async_trait, C>(
model: <Self::Entity as EntityTrait>::Model,
db: &'life0 C,
insert: bool,
) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
fn after_save<'life0, 'async_trait, C>(
model: <Self::Entity as EntityTrait>::Model,
db: &'life0 C,
insert: bool,
) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model, DbErr>> + Send + 'async_trait>>where
C: ConnectionTrait + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
Will be called after ActiveModel::insert, ActiveModel::update, and ActiveModel::save
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl ActiveModelBehavior for sea_orm::rbac::entity::permission::ActiveModel
Available on crate feature
rbac only.impl ActiveModelBehavior for sea_orm::rbac::entity::resource::ActiveModel
Available on crate feature
rbac only.impl ActiveModelBehavior for sea_orm::rbac::entity::role::ActiveModel
Available on crate feature
rbac only.impl ActiveModelBehavior for sea_orm::rbac::entity::role_hierarchy::ActiveModel
Available on crate feature
rbac only.impl ActiveModelBehavior for sea_orm::rbac::entity::role_permission::ActiveModel
Available on crate feature
rbac only.impl ActiveModelBehavior for sea_orm::rbac::entity::user_override::ActiveModel
Available on crate feature
rbac only.impl ActiveModelBehavior for sea_orm::rbac::entity::user_role::ActiveModel
Available on crate feature
rbac only.