pub trait SoftDeleteModel:
ModelTrait<Entity: SoftDelete<Model = Self>>
+ FromQueryResult
+ Send
+ Sync {
// Provided methods
fn is_trashed(&self) -> bool { ... }
fn soft_delete<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send { ... }
fn soft_delete_quietly<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send { ... }
fn restore<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send { ... }
fn restore_quietly<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send { ... }
fn force_delete<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<DeleteResult, DbErr>> + Send { ... }
fn force_delete_quietly<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<DeleteResult, DbErr>> + Send { ... }
}Expand description
Trash operations on one row. Every Model of a SoftDelete entity gets them.
use sea_orm::{DatabaseConnection, DbErr};
use sea_orm_soft_delete::SoftDeleteModel;
async fn example(db: &DatabaseConnection, post: posts::Model) -> Result<(), DbErr> {
let post = post.soft_delete(db).await?;
assert!(post.is_trashed());
let post = post.restore(db).await?;
Ok(())
}The plain methods run the entity’s hooks (SoftDelete::before_soft_delete
and friends); the *_quietly ones skip them.
Pass a DatabaseTransaction as db to make hooks and the change atomic.
Provided Methods§
Sourcefn is_trashed(&self) -> bool
fn is_trashed(&self) -> bool
Whether the row is in the trash.
Sourcefn soft_delete<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send
fn soft_delete<C: ConnectionTrait>( self, db: &C, ) -> impl Future<Output = Result<Self, DbErr>> + Send
Moves the row to the trash and returns it as stored. A row already in the
trash, even if this copy of it is out of date, keeps its deleted_at and runs
no after_soft_delete hook.
§Errors
When a query fails, the row no longer exists, or a hook returns an error.
Sourcefn soft_delete_quietly<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send
fn soft_delete_quietly<C: ConnectionTrait>( self, db: &C, ) -> impl Future<Output = Result<Self, DbErr>> + Send
Sourcefn restore<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send
fn restore<C: ConnectionTrait>( self, db: &C, ) -> impl Future<Output = Result<Self, DbErr>> + Send
Takes the row out of the trash and returns it as stored. A row that is not
trashed, even if this copy of it is out of date, runs no after_restore hook.
With unique_while_kept, restoring fails with a
unique violation when a kept row has taken the value meanwhile.
§Errors
When a query fails, the row no longer exists, or a hook returns an error.
Sourcefn restore_quietly<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<Self, DbErr>> + Send
fn restore_quietly<C: ConnectionTrait>( self, db: &C, ) -> impl Future<Output = Result<Self, DbErr>> + Send
Sourcefn force_delete<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<DeleteResult, DbErr>> + Send
fn force_delete<C: ConnectionTrait>( self, db: &C, ) -> impl Future<Output = Result<DeleteResult, DbErr>> + Send
Deletes the row for good, trashed or not. It bypasses ActiveModelBehavior,
so it still works when deny_hard_delete guards
the plain delete.
§Errors
When the query fails or a hook returns an error.
Sourcefn force_delete_quietly<C: ConnectionTrait>(
self,
db: &C,
) -> impl Future<Output = Result<DeleteResult, DbErr>> + Send
fn force_delete_quietly<C: ConnectionTrait>( self, db: &C, ) -> impl Future<Output = Result<DeleteResult, DbErr>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".