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.

Can `update()` return `[0]` when the row exists?

See original GitHub issue

For some reason calling Model.update(values, { where: ... }) returns [0] as if the updated row wasn’t found but at the same time Model.findOne({ where: ... }) returns the row and it is found.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
SimonSchickcommented, May 8, 2019

Was the row actually changed?

0reactions
MysteriousMsncommented, Sep 9, 2022

I am trying to update the totalLikes but getting [0]; await communityService.updateTotalLikes({ totalLikes }, { where: { id: communityId } });

communityService.updateTotalLikes = (data, query) => { return communityModel.update(data, query); };

Read more comments on GitHub >

github_iconTop Results From Across the Web

mySQL UPDATE query returns "0 rows affected"
If the such value already exists, mysql won't change it and will therefore return "0 rows affected". So be sure to also check...
Read more >
How to check if WHERE = value does not exist and make it ...
Another method: SELECT lineId FROM table_name WHERE lineId = 80 UNION ALL SELECT lineId FROM table_name WHERE lineId = 0 AND NOT EXISTS...
Read more >
UPDATE-if-exists, INSERT-if-not-exists (aka UPSERT) data ...
This filters the source table to only return one row for each CUSTOMER_ID. This enables the MERGE to work. De-duplicate the source rows...
Read more >
How to INSERT If Row Does Not Exist (UPSERT) in MySQL
Using INSERT ...​​ ON DUPLICATE KEY UPDATE is non-destructive, in that it will only ever issue INSERT or UPDATE statements, but never DELETE...
Read more >
13.2.15.6 Subqueries with EXISTS or NOT EXISTS
If a subquery returns any rows at all, EXISTS subquery is TRUE , and NOT ... In MySQL 8.0.19 and later, you can...
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