-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
model.save({ where })
#11254
Comments
What is this "versioning" you are referring to? |
https://sequelize.org/master/manual/models-definition.html#optimistic-locking Lines 3828 to 3830 in c32ac01
|
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
This issue is strongly related to #16158, where we discussed making the method throw an |
Is your feature request related to a problem? Please describe.
I want to save a model, but only if a condition still holds. An example of this would be versioning, which
model.save
already supports internally, but awhere
clause is more general.Describe the solution you'd like
model.save({where})
Why should this be in Sequelize
model.save
internally constructs aWHERE
clause consisting of the model's primary key and, optionally, versioning. The ability to add to that is very useful.Describe alternatives you've considered
Versioning is already supported by Sequelize, but it requires cooperation from the model (needs to have versioning enabled). It's also much more limited.
Model.update
can be used, but requires manually adding the instance's primary key to thewhere
clause:Usage example
Additional context
Would need to figure out what should happen if caller specified primary key in
where
. Should that override the primary key thatmodel.save
sets internally, or throw an error? Same for versioning.The text was updated successfully, but these errors were encountered: