1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use DbErr;
/// Turns `SeaORM`'s plain `delete` into an error, so a row of a soft-deletable
/// entity can only leave through [`soft_delete`](crate::SoftDeleteModel::soft_delete)
/// or, deliberately, [`force_delete`](crate::SoftDeleteModel::force_delete).
///
/// In Laravel `delete()` on a soft-deleting model is soft; in `SeaORM` it is not,
/// so one forgotten call would erase data. Call this from the entity's
/// `before_delete` hook:
///
/// ```
/// # mod posts {
/// # use sea_orm::entity::prelude::*;
/// # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
/// # #[sea_orm(table_name = "posts")]
/// # pub struct Model {
/// # #[sea_orm(primary_key)]
/// # pub id: i32,
/// # pub category_id: i32,
/// # pub slug: String,
/// # pub deleted_at: Option<DateTimeWithTimeZone>,
/// # }
/// # #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
/// # pub enum Relation {}
/// # }
/// # impl sea_orm_soft_delete::SoftDelete for posts::Entity {
/// # fn deleted_at_column() -> Self::Column { posts::Column::DeletedAt }
/// # }
/// use sea_orm::{ActiveModelBehavior, ConnectionTrait, DbErr};
///
/// #[async_trait::async_trait]
/// impl ActiveModelBehavior for posts::ActiveModel {
/// async fn before_delete<C: ConnectionTrait>(self, _db: &C) -> Result<Self, DbErr> {
/// sea_orm_soft_delete::deny_hard_delete()?;
/// Ok(self)
/// }
/// }
/// # fn main() {}
/// ```
///
/// # Errors
///
/// Always: that is its job.