Perform the `UPDATE` operation on an ActiveModel # Example (Postgres) ``` # 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_query_results([ # [fruit::Model { # id: 1, # name: "Orange".to_owned(), #
(self, db: &'a C)
| 394 | /// # } |
| 395 | /// ``` |
| 396 | async fn update<'a, C>(self, db: &'a C) -> Result<<Self::Entity as EntityTrait>::Model, DbErr> |
| 397 | where |
| 398 | <Self::Entity as EntityTrait>::Model: IntoActiveModel<Self>, |
| 399 | Self: ActiveModelBehavior + 'a, |
| 400 | C: ConnectionTrait, |
| 401 | { |
| 402 | let am = ActiveModelBehavior::before_save(self, db, false).await?; |
| 403 | let model: <Self::Entity as EntityTrait>::Model = Self::Entity::update(am).exec(db).await?; |
| 404 | Self::after_save(model, db, false).await |
| 405 | } |
| 406 | |
| 407 | /// Insert the model if primary key is `NotSet`, update otherwise. |
| 408 | /// Only works if the entity has auto increment primary key. |