pub trait ActiveModelBehavior: ActiveModelTrait {
// Provided methods
fn new() -> Self { ... }
fn before_save<C>(self, db: &C, insert: bool) -> Result<Self, DbErr>
where C: ConnectionTrait { ... }
fn after_save<C>(
model: <Self::Entity as EntityTrait>::Model,
db: &C,
insert: bool,
) -> Result<<Self::Entity as EntityTrait>::Model, DbErr>
where C: ConnectionTrait { ... }
fn before_delete<C>(self, db: &C) -> Result<Self, DbErr>
where C: ConnectionTrait { ... }
fn after_delete<C>(self, db: &C) -> Result<Self, DbErr>
where C: ConnectionTrait { ... }
}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<C>(self, db: &C, insert: bool) -> Result<Self, DbErr>where
C: ConnectionTrait,
fn before_save<C>(self, db: &C, insert: bool) -> Result<Self, DbErr>where
C: ConnectionTrait,
Will be called before ActiveModel::insert, ActiveModel::update, and ActiveModel::save
Sourcefn after_save<C>(
model: <Self::Entity as EntityTrait>::Model,
db: &C,
insert: bool,
) -> Result<<Self::Entity as EntityTrait>::Model, DbErr>where
C: ConnectionTrait,
fn after_save<C>(
model: <Self::Entity as EntityTrait>::Model,
db: &C,
insert: bool,
) -> Result<<Self::Entity as EntityTrait>::Model, DbErr>where
C: ConnectionTrait,
Will be called after ActiveModel::insert, ActiveModel::update, and ActiveModel::save
Sourcefn before_delete<C>(self, db: &C) -> Result<Self, DbErr>where
C: ConnectionTrait,
fn before_delete<C>(self, db: &C) -> Result<Self, DbErr>where
C: ConnectionTrait,
Will be called before ActiveModel::delete
Sourcefn after_delete<C>(self, db: &C) -> Result<Self, DbErr>where
C: ConnectionTrait,
fn after_delete<C>(self, db: &C) -> Result<Self, DbErr>where
C: ConnectionTrait,
Will be called after ActiveModel::delete
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.