Skip to main content
Version: 0.6.x 🚧


Update One

You will get a Model from find result. If you want to save the model back into the database, you need to convert it into an ActiveModel first. The generated query will only include the Set attributes.

let pear: Option<fruit::Model> = Fruit::find_by_id(28).one(db).await?;

// Into ActiveModel
let mut pear: fruit::ActiveModel = pear.unwrap().into();

// Update name attribute = Set("Sweet pear".to_owned());

// Update corresponding row in database using primary key value
let pear: fruit::Model = pear.update(db).await?;

Update Many

You can also update multiple rows in the database without finding each Model with SeaORM select.

// Bulk set attributes using ActiveModel
let update_result: UpdateResult = Fruit::update_many()

// UPDATE `fruit` SET `cake_id` = NULL WHERE `fruit`.`name` LIKE '%Apple%'
.col_expr(fruit::Column::CakeId, Expr::value(Value::Null))