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

findOrCreate returns an Array of Instances intead of just one Instance #72

Open
ligreman opened this issue Apr 17, 2019 · 0 comments
Open

Comments

@ligreman
Copy link

Sequelize findOrCreate function looks for one element and if it is found, returns an Array that contains [elementFound, created].

Where elementFound is an Instance and created is a boolean. If the conditions of the query match more than one element, it just returns the first one (array index 0), like noted in the comment:

In the example above, the array spread on line 3 divides the array into its 2 parts and passes them
as arguments to the callback function defined beginning at line 39, which treats them as "user" and
"created" in this case. (So "user" will be the object from index 0 of the returned array and
"created" will equal "true".)

http://docs.sequelizejs.com/manual/models-usage.html

In Sequelize-mock docs the findOrCreate reflects that it returns Promise.<Array.<Instance, Boolean>> but it actually returns Promise.<Array.<Array<Instance>, Boolean>>.

That second Array is not supposed to be there. Must return the 0 index of that array.

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

1 participant