Skip to content
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

Where should not be required in Model#update() #2340

Closed
overlookmotel opened this issue Sep 23, 2014 · 8 comments
Closed

Where should not be required in Model#update() #2340

overlookmotel opened this issue Sep 23, 2014 · 8 comments

Comments

@overlookmotel
Copy link
Contributor

I just noticed that providing a where parameter in the options passed to Model#update() is required. The following throws an error:

Folder.update({name: 'bob'})

This doesn't allow you to update all rows in a table simultaneously, which sometimes you might want to do. Should this be the case?

@overlookmotel
Copy link
Contributor Author

Of course, you can do:

Folder.update({name: 'bob'}, {where: {}})

My silly.

@janmeier
Copy link
Member

Yep, an empty where object was the idea. I made the where required to make the API change

@mickhansen
Copy link
Contributor

It's also a pretty good sanity check.

@gorangajic
Copy link
Contributor

why then throw a new Error?

throw new Error('Missing where attribute in the options parameter passed to update.');

options = options || {};
options.where = options.where || {};

I can create a pull request if you want?

@gorangajic
Copy link
Contributor

btw this

Folder.update({name: 'bob'}, {where: {}})

does not work for me
stacktrace - https://gist.github.com/feroc1ty/21ed43095bc145c40135

@janmeier
Copy link
Member

The where is required to make sure the user actually wants to update all rows

@gorangajic
Copy link
Contributor

query

postgres Executing (default): UPDATE "Users" SET "something"=0,"updatedAt"='2015-02-11 11:54:48.880 +00:00' WHERE

@mickhansen
Copy link
Contributor

@Feroc1ty seems there's an error in the query generator :)
Please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants