Skip to content
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

Insert & Update Return Model instead of ActiveModel #327

Closed
billy1624 opened this issue Nov 19, 2021 · 2 comments
Closed

Insert & Update Return Model instead of ActiveModel #327

billy1624 opened this issue Nov 19, 2021 · 2 comments
Milestone

Comments

@billy1624
Copy link
Member

I wonder, since RETURNING support the methods return ActiveModels, wouldn't it be better to just return Models instead ? ActiveModel is better suited for inputs and Model for output, and it would make things more aligned with select. Also it is easy to convert from Model into ActiveModel, but not the other way around

It would also open possibility for convergence with QuerySelect/Select traits, so that we can write:

fruit::Entity::update(orange.clone())
        .filter(fruit::Column::Name.contains("orange"))
        .column_as(fruit::Column::Name, "foo")
        .into_model::<MyOrangeModel>()
        .exec(&db)
        .await

Originally posted by @nicoulaj on Discord

@billy1624
Copy link
Member Author

You made a good point! One blocker is that ActiveModelBehavior's before_* & after_* operations takes ActiveModel instead of Model. https://docs.rs/sea-orm/0.3.2/sea_orm/entity/trait.ActiveModelBehavior.html

I guess we could do is to change before_* taking ActiveModel, while after_* taking Model.

How is that sounds?

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 19, 2021

duplicate of #289

@tyt2y3 tyt2y3 closed this as completed Nov 19, 2021
@tyt2y3 tyt2y3 added this to the 0.5.x - Schema milestone Nov 19, 2021
@billy1624 billy1624 modified the milestone: 0.5.x - Schema Nov 25, 2021
@billy1624 billy1624 linked a pull request Dec 21, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants