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

Why insert, update, etc return a ActiveModel instead of Model? #289

Closed
edg-l opened this issue Nov 2, 2021 · 3 comments · Fixed by #339 or #396
Closed

Why insert, update, etc return a ActiveModel instead of Model? #289

edg-l opened this issue Nov 2, 2021 · 3 comments · Fixed by #339 or #396
Assignees
Milestone

Comments

@edg-l
Copy link

edg-l commented Nov 2, 2021

I find it curious, since you can easily go from a model to a activemodel, but not backwards (from what i've seen), and most of the time after a insert i want the Model which i can return from my api.

I've seen the impl of the insert model and it in fact does a query to find the inserted model and then it converts it to a activemodel, I think we should let the end user decide whether to convert it to a activemodel or not and just return a model.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

You have made a good point! I agree that the conversion could seem unnecessary.

For now, the returned object of 'update' is the input ActiveModel.

So may be it makes sense that the return type of 'model.insert()' is Self.

And they also trigger the ActiveModelBehavior

Do you have new thoughts on it?

@Paul-Vandell
Copy link

Paul-Vandell commented Nov 2, 2021

+1 here. So finally we have to make a double select query to get back the last inserted user as Model finally right ? related to #148

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 4, 2021

Thanks for the input. We thought about it, and our plan for now is to introduce a InsertModel::insert() method that does not involve ActiveModel; same applies to UpdateModel::update().

@billy1624 billy1624 added this to the 0.5.x - Schema milestone Nov 22, 2021
@billy1624 billy1624 self-assigned this Nov 30, 2021
@billy1624 billy1624 linked a pull request Dec 21, 2021 that will close this issue
arpancodes pushed a commit to arpancodes/sea-orm that referenced this issue Apr 8, 2022
* issues-142 full support lock in select

* issues-142 Fix struct name

* issues-142 Fix test

* issues-280 Revert t previous commit
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

Successfully merging a pull request may close this issue.

4 participants