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
Is there a way to do a PATCH of an entity? #229
Comments
I think that update will do exactly that: remult.repo(MyEnity).update(id, {isActive:true}) Another option is change a member and send the update: let myEntity = remult.repo(MyEntity).findFirst()
myEntity.isActive=true
remult.repo(MyEntity).save(myEntity) |
I tried and it works, just the HTTP method is a PUT instead of a PATCH, but it does the job. |
@noam-honig Is update supposed to keep all fields that are not specified intact? It seems to me that in some circumstances other fields get overwritten (perhaps primitive types and/or allowNull?). Indeed, in the PUT network request some other fields (not specified in the second parameter of update) are specified with null values. |
@groszdaniel yes - unspecified fields shoud stay intact. If not, it's a bug and I would like to fix it. |
@noam-honig I made a simple example based on the React starter project: https://github.com/groszdaniel/remult-update-bug One entity, two integer fields, each button is supposed to increment one without touching the other. Instead, when one is incremented, the other becomes 0. In the network request, you can see that a 0 is sent for the unspecified field. (Not in the example, but strings are set to an empty string, for instance.) The allowNull option doesn't actually matter. If you fix this, I suggest also updating the documentation to make it clear that it's allowed to only specify some fields. Currently, all examples specify unchanged fields like this: |
Thanks. I'm out of town, will look at it tomorrow |
Sorry about that, this issue was already fixed in version: My bad for not updating the starter kit - will do that now |
Hello,
I was trying to update a single attribute of an entity but I just see update or save and they send all the attributes of the object in the payload. For example it would be nice to have something like:
remult.repo(MyEntity).patch(id, {isActive: true});
Thank you
The text was updated successfully, but these errors were encountered: