I'm cleaning up some sequelize
code and the findOrCreate
function returns a promise that requires spreading to get the actual result object.
I'd like to rewrite my code to use await
instead and, given ES6 supports array destructuring I'd have thought that instead of
User.findOrCreate({ where: { mcId }, defaults }).spread((user, created) => {
// do stuff
})
I'd just be able to do
const [user, created] = await User.findOrCreate({ where: { mcId }, defaults })
but alas that's not the case.
I get the error (intermediate value) is not iterable
Is there any special trick to doing this or is what I am trying to do just not possible?
I'm using Sequelize v4.37.10 and this worked for me -
const [address, created] = await models.Address.findOrCreate({ where: { pid: 123}, defaults});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With