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.

findAll returns nothing while generated MySQL returns multiple.

See original GitHub issue

This is a very strange problem that I have been trying to hunt down for a few days now and have been all over the internet.

The following code returns no records (incorrect). If I copy and paste the raw sequelize generated MySQL and paste it into the database console, I get 20 records (correct). I would like to know what could possibly be contributing to this sort of error. If I change the where clause to a different value or different column then it works as expected. The error only happens for a few specific values with this specific column.

return models.Examination.findAll({
    include:[
        {
            model: models.Event,
            where: {
                sample_id: 23
            }
        }
    ]
});

I can verify that all 20 records returned by the console do in fact have a valid sample_id of 23 so there is nothing strange going on there. As I mentioned earlier, the raw sequelize output works fine, but the value returned by ‘findAll’ is incorrect.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ngorsecommented, Nov 19, 2020

Hello. We are experimenting the same issue. Disabling sync() does not solve it. Any clue of what else it could be?

1reaction
nullgrimcommented, Dec 10, 2022

To solve this issue I moved one of the included models with a “where” clause at the bottom of the array.

Personally, I have two includes that have a where clause, yet only one of them was causing this issue. Another thing I would like to point out is if you use the “raw” option it also fixes this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize findAll query returning incorrect results
findAll query through Sequelize when the link is clicked. My query is intended to findAll possible matches of both email addresses and ...
Read more >
Raw Queries - Sequelize
However, two arguments will always be returned, but for MSSQL and MySQL it will be two references to the same object.
Read more >
How To Use Sequelize with Node.js and MySQL - DigitalOcean
You successfully used the Sequelize findAll() method to return all book data from the database. Selecting with the where Clause. In this section ......
Read more >
Four Sequelize Associations You Should Know
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, ... FULL OUTER JOIN: Returns all records when there is a match in ......
Read more >
Querying - Manual | Sequelize
Querying. Attributes. To select only some attributes, you can use the attributes option. Most often, you pass an array: Model.findAll({ attributes: ['foo' ...
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