-
Notifications
You must be signed in to change notification settings - Fork 362
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
Provide feedback (result count) for updateAll and destroyAll #321
Conversation
@raymondfeng shouldn't |
I think we can return the number of records deleted for removeById too. |
I don't think a HTTP 200 with { count: 1 }, makes sense in this case, it is a singular resource. I'd prefer HTTP 404 if the item doesn't exist in the first place, and a 500-type error if it failed to delete. And of course a 403 one if ACL's forbid. |
DELETE /api/orders/1 usually produces 204 or 404 depending on if the order 1 is found. I think we can return the count in Node.js callback but translate it to 204 or 404 for REST. |
204 or 404 for REST is OK, however, why not return a (pure) boolean instead of 0 or 1 in Node.js? |
|
@raymondfeng updated - enabling this in the REST API is probably a breaking change though. |
We still have to fix connectors to return the count too. |
@raymondfeng from what I've seen loopback-connector-mongodb already does. Not sure about the SQL ones, but they (Postgres) receive a result that is passed to the callback. |
Most SQL based connectors already set a property to track the number of changed/affected rows. But we need to make the property name consistent. For example,
|
@fabien I assume we need to fix all connectors before we can land this patch. What do you think? |
@raymondfeng yes - wish I had the time to work on that right now, though! |
The only remaining piece in this patch is reporting whether "deleteById" deleted the record or whether the record was already deleted. Considering that this PR has been stale for more than 4 months, I am closing it. @fabien please send a new pull request when you get time to implement feedback in "deleteById". |
@bajtos @raymondfeng how should we handle the return value for We should do one of the following:
OR:
|
Reporting as an error seems to be more appropriate to me. |
@raymondfeng want me to create a PR? |
Reporting as an error is IMO a breaking change. When I want to delete a record, then the fact that it was already deleted is usually not important. |
Don't forget to update |
@bajtos so you're not interested in knowing if it succeeded the first time? ... |
If it's a breaking change (because the error will propagate to the REST API), I'm find with |
Now propotype.delete takes an
|
@raymondfeng what will be the error message? |
Something like 'No instance found for id idValue' |
Can you enlighten me and describe a situation when you want the delete operation to fail when the record is already not there? Hiding this behaviour behind a flag is a reasonable compromise allowing users to choose the flavour they prefer. Although it won't be available via REST API (at least not now), so perhaps a per-model option (setting) or a global loopback option would make more sense? |
Well, for the same reasons you'd like to know how many items you deleted doing We can always add such a setting or global option later. If it weren't for @raymondfeng to bring the Error option up, I would have omitted error reporting for this first pass anyway. |
This currently targets the Memory connector and fixes #294 - it appears that the MongoDB connector already does the right thing. We'd have to check the other connectors (running test/manipulation.test.js will fail if unsupported).
This is the first step towards more meaningful feedback from the (HTTP) API as well (needs loopback update, for remoting return values).