Error: Include unexpected. Element has to be either a Model, an Association or an object.
See original GitHub issueIssue Description
I am trying to make a big query with many joins and it seems sequelize doesn’t like the way I am doing this.
What are you doing?
const ids = [/*Some integer here*/];
models.Exercise.findAll({
// no need for that part here
attributes: [
"id",
"title",
"description",
"version",
"createdAt",
"updatedAt"
],
where: {
id: {
[Op.in]: ids
}
},
include: [
// load exercise evaluation
{
models: models.Exercise_Metrics,
as: "metrics",
attributes: [
["vote_count", "votes"],
["avg_vote_score", "avg_vote"]
]
},
// load tags linked to this exercise ( with their category included )
{
models: models.Exercise_Tag,
as: "tags",
attributes: [],
include: [
{
models: models.Tag,
attributes: ["id", "text"],
include: [
{
models: models.Tag_Category,
as: "category",
attributes: [
["kind", "category"],
["id", "category_id"]
]
}
]
}
]
}
]
});
What do you expect to happen?
I expect that to work when I use findAll
What is actually happening?
Error: Include unexpected. Element has to be either a Model, an Association or an object.
at Function._conformInclude (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:390:11)
at options.include.options.include.map.include (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:326:59)
at Array.map (<anonymous>)
at Function._conformIncludes (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:326:39)
at Function._baseMerge (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:791:10)
at Function._defaultsOptions (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:828:17)
at Function._injectScope (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:3288:10)
at Promise.try (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:1707:12)
at tryCatcher (D:\workspaceshit\exercises_library\node_modules\bluebird\js\release\util.js:16:23)
at Function.Promise.attempt.Promise.try (D:\workspaceshit\exercises_library\node_modules\bluebird\js\release\method.js:39:29)
at Function.findAll (D:\workspaceshit\exercises_library\node_modules\sequelize\lib\model.js:1706:23)
Additional context
Here are my models definitions if It could help you : Exercise Exercise_Metrics Exercise_Tag Tag Tag_Category
Environment
- Sequelize version: 5.21.2
- Node.js version: v10.16.0
- Operating System: Windows 10
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 4 years ago
- Comments:72 (1 by maintainers)
Top Results From Across the Web
Sequelize Error: Include unexpected. Element has to be either ...
Element has to be either a Model, an Association or an object. My Models look like this: module.exports = (sequelize, Sequelize) => {...
Read more >Sequelize.js: Include unexpected. Element has to be either a ...
Coding example for the question Sequelize.js: Include unexpected. Element has to be either a Model, an Association or an object-node.js.
Read more >Include unexpected. Element has to be either a Model, an ...
TypeError: Router.use() requires a middleware function but got a Object routes폴더의 파일 마지막에 const express = require('express'); const ...
Read more >Eager Loading - Sequelize
As briefly mentioned in the associations guide, eager Loading is the act of querying data of several models at once (one 'main' model...
Read more >javascript - Sequelize INNER JOIN - Stack Overflow
After gived Error: Include unexpected. Element has to be either a Model, an Association or an object. Users.hasMany(Payments, { foreignKey: " ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I made a typo :
models
instead ofmodel
Sorry for the issueI had the issue but it was because i did not use the proper name for the model name use that i defined it as
in my model i defined it as sequelize.define(‘houseLocation’
and in query i had lower “l”
Once i used the correct case as I had in the in model then it work. Check the name you gave it in the define bit in the model and check your case