Delete an active model by its primary key # Example ``` # use sea_orm::{error::*, tests_cfg::*, *}; # # #[smol_potat::main] # #[cfg(feature = "mock")] # pub async fn main() -> Result<(), DbErr> { # # let db = MockDatabase::new(DbBackend::Postgres) # .append_exec_results([ # MockExecResult { # last_insert_id: 0, # rows_affected: 1, # }, # ]) # .
(self, db: &'a C)
| 472 | /// # } |
| 473 | /// ``` |
| 474 | async fn delete<'a, C>(self, db: &'a C) -> Result<DeleteResult, DbErr> |
| 475 | where |
| 476 | Self: ActiveModelBehavior + 'a, |
| 477 | C: ConnectionTrait, |
| 478 | { |
| 479 | let am = ActiveModelBehavior::before_delete(self, db).await?; |
| 480 | let am_clone = am.clone(); |
| 481 | let delete_res = Self::Entity::delete(am).exec(db).await?; |
| 482 | ActiveModelBehavior::after_delete(am_clone, db).await?; |
| 483 | Ok(delete_res) |
| 484 | } |
| 485 | |
| 486 | /// Set the corresponding attributes in the ActiveModel from a JSON value |
| 487 | /// |