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) -> &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§

source

fn new() -> Self

Create a new ActiveModel with default values. Also used by Default::default().

source

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

source

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

source

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,

Will be called before ActiveModel::delete

source

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,

Will be called after ActiveModel::delete

Object Safety§

This trait is not object safe.

Implementors§