diff --git a/SeaORM/docs/03-generate-entity/03-expanded-entity-structure.md b/SeaORM/docs/03-generate-entity/03-expanded-entity-structure.md index ff305608ccf..55533e8a3fb 100644 --- a/SeaORM/docs/03-generate-entity/03-expanded-entity-structure.md +++ b/SeaORM/docs/03-generate-entity/03-expanded-entity-structure.md @@ -153,22 +153,37 @@ Handler for different actions on an `ActiveModel`. impl ActiveModelBehavior for ActiveModel { /// Create a new ActiveModel with default values. Also used by `Default::default()`. fn new() -> Self { - ::default() + Self { + uuid: Set(Uuid::new_v4()), + ..ActiveModelTrait::default() + } + } + + /// Will be triggered before insert / update + fn before_save(self, insert: bool) -> Result { + if self.price.as_ref() <= &0.0 { + Err(DbErr::Custom(format!( + "[before_save] Invalid Price, insert: {}", + insert + ))) + } else { + Ok(self) + } } - /// Will be called before saving - fn before_save(self) -> Self { - self + /// Will be triggered after insert / update + fn after_save(self, insert: bool) -> Result { + Ok(self) } - /// Will be called after saving - fn after_save(self) -> Self { - self + /// Will be triggered before delete + fn before_delete(self) -> Result { + Ok(self) } - /// Will be called before deleting - fn before_delete(self) -> Self { - self + /// Will be triggered after delete + fn after_delete(self) -> Result { + Ok(self) } } ```