-
-
Notifications
You must be signed in to change notification settings - Fork 539
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
Remove implicit filter in update method #129
Comments
Yes, this is the case.
I think we better use Rust's type system to handle this instead of throwing panic during runtime, as discussed earlier.
I think we can add a functionality to reset the filter. Fruit::update(pear)
.reset_filter()
.filter(fruit::Column::Id.eq(123))
.exec(db).await?;
Agree! |
I agree on this behavior indeed. |
However, this will be a huge breaking change for those who are using
|
I think it's great to make these kind of changes at this time as SeaORM was released so recently.. so I think these changes are worth it! |
Lines 261 to 291 in f56ac7b
After a third thought, I came to a solution that we don't need to change existing behavior, while still does what you were asking for. |
Works for you? @acidic9 |
Although it's not my preferred final API, it does work. Would be lovely if other people contribute their opinions too |
Close for now. To whom may stumble upon, feel free to leave a comment. |
TLDR;
Instead of using the
Set
primary key in an active model for updating an entity, use a manual.filter
method.And add a new method directly to an
ActiveModel
which uses theSet
primary key.Currently to perform an update on multiple fields, it looks like you do it with:
But if you want to update 10 columns, do you need to manually add
.col_expr
for each column?And doing the following will update the pears name with the ID
123
.The issue with this, is that if the id is not set, a panic will occur.
https://github.com/SeaQL/sea-orm/blob/de1f5d397df26659ef11ee9cc97251964503c748/src/query/update.rs#L89-97
But perhaps it'd make sense for the API to remove the lines 89 - 97 (in the link above) and force the user to explicitly add the
WHERE id = '...'
clause:The benefit of this, is it allows users to write more complex filtering rather than a simple
id = ...
.The down side is that if the ActiveModel has the ID as
Set
... then it'll actually try to update the ID in the query. But I don't consider this so much as a down side, because some people may actually want to update a primary key.The active model could have an
.update
method which could keep the current behaviour and use the set primary key to perform an update.Eg:
The text was updated successfully, but these errors were encountered: