You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
findAndCountAll crashes with a query which runs in findAll #4194
User.findAndCountAll({
where: sequelize.literal('profiles.userId IS null'),
include: [Profile]
})
I get the following error:
Executing (default): SELECT count(*) AS `count` FROM `users` AS `user` WHERE profiles.userId IS null;
Unhandled rejection SequelizeDatabaseError: SQLITE_ERROR: no such column: profiles.userId
at Query.formatError (.../node_modules/sequelize/lib/dialects/sqlite/query.js:242:14)
at .../node_modules/sequelize/lib/dialects/sqlite/query.js:47:29
at replacement (.../node_modules/sqlite3/lib/trace.js:20:31)
at Statement.errBack (.../node_modules/sqlite3/lib/sqlite3.js:16:21)
It seems the whole include is ignored during count. As if a different query was ran.
I have just updated to 3.5
Before I had something along those lines (sql-string.js:144 error undefined is not a function)
If there are any constraints directly on the include (include.where) the include is marked as required, and thus not removed. But in this case, there is no way to identify that the include is required.
Activity
janmeier commentedon Jul 27, 2015
How will it not run?
slawo commentedon Jul 27, 2015
@janmeier, when running :
I get the following error:
It seems the whole include is ignored during count. As if a different query was ran.
I have just updated to 3.5
Before I had something along those lines (
sql-string.js:144 error undefined is not a function)janmeier commentedon Jul 27, 2015
That's because we remove non-required includes, in order to make the count query faster.
You could make the include required:
include: [{ model: Profile, required: true}]. But note that this converts the include from a left to inner joinslawo commentedon Jul 27, 2015
@janmeier So basically any constraints in the include are then ignored and the count is simply false?
This doesn't sound like an expected behaviour.
janmeier commentedon Jul 27, 2015
If there are any constraints directly on the include (
include.where) the include is marked as required, and thus not removed. But in this case, there is no way to identify that the include is required.http://docs.sequelizejs.com/en/latest/api/model/#findandcountfindoptions-promiseobject
slawo commentedon Jul 27, 2015
@janmeier, are there other places where this type of optimisation is done?
Adding a keyword fo force sequelize keep the include could be useful:
include: [ { model: Profile, keep:true} ]Without changing the type of join that is.
slawo commentedon Jul 27, 2015
@janmeier Actually a much more elegant solution would be to use the required option like this:
This way there is no new option, and this obviously means we want to force sequelize to use the left join whatever happens.
What do you think of this idea?
Solves an issue with left joins being opptimised away in some queries.