Sea-ORM provides ActiveModelBehavior for hooks (before_save/after_save) and derived methods for common access patterns.
ActiveModelBehavior
impl ActiveModelBehavior for ActiveModel {
fn before_save<C>(self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
let mut this = self;
if insert {
// Set creation timestamp on insert
this.created_at = Set(chrono::Utc::now());
}
// Always update the updated_at timestamp
this.updated_at = Set(chrono::Utc::now());
Ok(this)
}
}