Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Implement insert & update for ActiveModel #110

Closed
billy1624 opened this issue Aug 27, 2021 · 1 comment · Fixed by #132
Closed

Implement insert & update for ActiveModel #110

billy1624 opened this issue Aug 27, 2021 · 1 comment · Fixed by #132

Comments

@billy1624
Copy link
Member

To avoid manually exec the insert ActiveModel. In below, we cannot simply save it because this is a junction table and the composite primary key should be set during insert.

let bobby_cakes_bakers = cakes_bakers::ActiveModel {
cake_id: Set(chocolate_cake_res.last_insert_id as i32),
baker_id: Set(baker_bobby_res.last_insert_id as i32),
..Default::default()
};
CakesBakers::insert(bobby_cakes_bakers)
.exec(&ctx.db)
.await?;

Perhaps impl it here

impl ActiveModel {
pub async fn save(self, db: &sea_orm::DatabaseConnection) -> Result<Self, sea_orm::DbErr> {
sea_orm::save_active_model::<Self, Entity>(self, db).await
}
pub async fn delete(self, db: &sea_orm::DatabaseConnection) -> Result<sea_orm::DeleteResult, sea_orm::DbErr> {
sea_orm::delete_active_model::<Self, Entity>(self, db).await
}
}

@tyt2y3
Copy link
Member

tyt2y3 commented Aug 28, 2021

What is the final intended API?
I kind of get the problem, but I don't get the proposed solution.

@SeaQL SeaQL locked and limited conversation to collaborators Sep 4, 2021
@tyt2y3 tyt2y3 closed this as completed Sep 4, 2021
@SeaQL SeaQL unlocked this conversation Sep 10, 2021
@SeaQL SeaQL locked as resolved and limited conversation to collaborators Sep 10, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants