question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

update() breaks when sequelize configured with raw:true

See original GitHub issue

Affects master, v1.4.3, etc.

A call to update() results in a Model.findById call: https://github.com/feathersjs/feathers-sequelize/blob/master/src/index.js#L168

If sequelize is configured with raw: false (the default), this returns a DAO, with a toJSON method, which is then called several lines later: https://github.com/feathersjs/feathers-sequelize/blob/master/src/index.js#L174

However, if sequelize is configured with raw: true, the findById call returns a JSON object without this method.

There are two simple fixes:

  1. Only call toJSON if it exists and is a function
  2. pass {raw: false} as a second argument to the findById call to force the expected behaviour

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
dafflcommented, Mar 24, 2017

Makes sense. This can probably easily be fixed by changing the line you pointed out to

Object.keys(typeof instance.toJSON === 'function' ? instance.toJSON() : instance).forEach(key => {
1reaction
dafflcommented, Mar 25, 2017

Ah, I see. Well at least we know it didn’t break anything else 😉

I think we should do what patch does and use this.Model.update(omit(data, this.id), options) instead of calling save on the model instance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use 'sequelize.sync()' without difficulties - Medium
After executing migrate command, you get database that is fully set up. $ npx sequelize db:migrate. Don't fortget to remove 'sync()' option from ......
Read more >
Upgrade to v6 - Sequelize
Sequelize v6 is the next major release after v5. Below is a list of breaking changes to help you upgrade.
Read more >
Manual | Sequelize - ESDoc Hosting Service
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, ... In this tutorial you will learn to make a simple setup of...
Read more >
Create or Update Sequelize - Stack Overflow
Basically I have a array of objects and a could use the BulkCreate() method. But as the Cron starts again, it doesn't solve...
Read more >
sequelize update record and return value Code Example
Result is array because we have used findAll. We can use findOne as well if you want one row and update that. 9....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found