logo
pub trait ActiveModelBehavior: ActiveModelTrait {
    fn new() -> Self { ... }
    fn before_save(self, insert: bool) -> Result<Self, DbErr> { ... }
    fn after_save(
        model: <Self::Entity as EntityTrait>::Model,
        insert: bool
    ) -> Result<<Self::Entity as EntityTrait>::Model, DbErr> { ... } fn before_delete(self) -> Result<Self, DbErr> { ... } fn after_delete(self) -> Result<Self, DbErr> { ... } }
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

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

Will be called before saving

Will be called after saving

Will be called before deleting

Will be called after deleting

Implementors