-
-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update / Delete by id #552
Comments
Hey @Ilqjx, interesting idea! For delete, I think it's make sense to delete by id. I support adding a new API for it. For update, I would say it's natural to select the ActiveModel from db then alter the row then save it back to db. let orange: Option<fruit::Model> = Fruit::find_by_id(30).one(db).await?;
let orange: fruit::Model = orange.unwrap();
let res: DeleteResult = orange.delete(db).await?;
assert_eq!(res.rows_affected, 1); Or, update any rows exists that match specific conditions. // Bulk set attributes using ActiveModel
let update_result: UpdateResult = Fruit::update_many()
.set(pear)
.filter(fruit::Column::Id.eq(1))
.exec(db)
.await?;
// UPDATE `fruit` SET `cake_id` = NULL WHERE `fruit`.`name` LIKE '%Apple%'
Fruit::update_many()
.col_expr(fruit::Column::CakeId, Expr::value(Value::Null))
.filter(fruit::Column::Name.contains("Apple"))
.exec(db)
.await?; I'm not sure how |
Indeed, delete is useful and update is unnecessary. |
I will open this issue for contributions :) |
I'd like to work on this @billy1624 |
Hey @AbhijithGanesh, thanks for the interest!! The I saw your message on Discord, you want to work on the |
I agree with llqjx |
Is there something like
find_by_id(1).one(&db)
forupdate
anddelete
?Look like
update_by_id(1).one(&db)
anddelete_by_id(1).one(&db)
.The text was updated successfully, but these errors were encountered: