-
Notifications
You must be signed in to change notification settings - Fork 55
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 remove always supposed to return true? #239
Comments
Yes, if there's no error, you'll get a |
Ah, hmmm. As I said I'm still new to SQL. Feel like I'm learning it pretty fast now that I'm doing it all day, but I had just assumed it'd error out if nothing was found. In this case, I'm not sure what the majority of people do. You'd have way more experience in that realm :) so far everywhere I do a remove I first do a |
Oh, but, if that was a super common pattern (Model.first() and only if data Model.remove()) I may suggest a method that does both in one call. If I'm doing it wrong then I'd stick with the current setup |
I'm not a SQL expert, but with SQL a SELECT and a REMOVE with conditions work essentially the same. If you SELECT with conditions that don't match any entries in the DB, it returns nothing. If you DELETE with conditions that match nothing, it deletes nothing. Think of it like an As far as the standard for REST APIs, and removal of a non-existing item, I'm not sure -- REST is super-minimal, and leaves a lot of edge cases unspecified. 404 is probably fine in the case where you try to remove something that isn't there in the first place. Creating a special method to do that might be problematic however in that for the non-relational DBs, you already have to do an initial fetch based on your conditions to get the id(s) of the things to remove. This is basically the opposite side to your problem with SQL adapters. HAVING SAID ALL THIS, after doing a little sleuthing around, it appears that Postgres (and perhaps other SQLs as well) are capable of returning a value for the affected rows after an UPDATE or DELETE. I can have a look and see how easy that would be to plug into our true/false return value -- and I should add that a pull request for this would be happily accepted. :D |
Any news on this one? There is 'affectedRows' on most SQL libraries, so I would be happy to have this true result of the operation :) |
Sorry, I'm totally underwater with my new job -- I'd happily merge a PR that implements this. |
I'm trying to figure out if remove was actually successful but it seems like I can pretty much pass anything to it and it'll say everything went well. Unless the DB is down, no
err
s are fired and the 2nd "data" param just always returns true. Or, maybe this is a normal thing for adapters to do?The text was updated successfully, but these errors were encountered: