Repository navigation
Closed
Description
What you are doing?
I'm attempting to create an association via an api interface that I have created.
What do you expect to happen?
It should've just found the user and continued on, but it seems the include is causing an issue, however just calling the "find" method from other tests appears to work just fine, so I'm not really sure what is going on.
What is actually happening?
I'm getting a Sequelize error that looks like to be failing when the table name is retrieved from the included models.
sentinel:api:user TypeError: Cannot read property 'getTableName' of undefined
at validateIncludedElement (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\lib\model.js:505:27)
at C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\lib\model.js:432:29
at Array.map (native)
at validateIncludedElements (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\lib\model.js:428:37)
at null.<anonymous> (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\lib\model.js:1364:32)
at tryCatcher (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:502:31)
at Promise._settlePromise (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:559:18)
at Promise._settlePromise0 (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:604:10)
at Promise._settlePromises (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:683:18)
at Async._drainQueue (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\async.js:138:16)
at Async._drainQueues (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\async.js:148:10)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\Kieron\Dracade\web\sentinel\node_modules\sequelize\node_modules\bluebird\js\release\async.js:17:14)
at processImmediate [as _immediateCallback] (timers.js:383:17) +86ms
The error originates from this test, however it's actually thrown here from here.
Dialect: mysql
Database version: 10.1.8-MariaDB
Sequelize version: 3.23.3
Reacted by trockz
Metadata
Metadata
Assignees
Labels
No labels
Activity
janmeier commentedon Jun 18, 2016
Most likely the model you are trying to include is undefined. Please add some code that reproduces the issue
xKrvZ commentedon Jun 18, 2016
@janmeier I doubt it, I added
console.log(options.include.AuthorizationPolicy.getTableName());here and it showed the table name as expected, however the query still failed to getTableName.It's either an issue with Sequelize or it has something to do with the way my application is currently loading models.
In regards to code that reproduces the error, could you not just clone the repository I provided?
xKrvZ commentedon Jun 18, 2016
Okay, so after a little debugging of my own, I think it has something to do with the way my associations are setup, my models are apparent when I associate them with each other, so I'm not 100% sure.
So what I did was add this line
include = include[Object.keys(include)[0]];here, and it then gave me this error:It's stating that my
authorization_user_policytable is not associated to AuthorizationPolicy, but they are associated according to the SQL schema.xKrvZ commentedon Jun 18, 2016
Solved
The issue was that I was passing 'include' through as an object and not an array.
justechn commentedon Nov 1, 2016
I just ran into this myself. This could really use a better error message, the one provided makes no sense.
janmeier commentedon Nov 1, 2016
@justechn I understand your sentiment, but having to monkeypatch type checking of all arguments ( and their arbitrarily nested children) is not feasible in my mind
trevorh2007 commentedon Mar 14, 2018
To add on to this I ran into this similar situation. Same error, same console logging results. My issue was
that there was no join table that 'through' could use, so just getting rid of 'through' like this:
Solved my issue
heisian commentedon Mar 20, 2018
Howcome there is no visibility into what model Sequelize is actually trying to access here?
Why doesn't it say something like
call to Model.getTableName() failed?calintamas commentedon Aug 29, 2018
In the
associatefunction, make sure to add the through model using a simple string and not the model object. That was the issue in my case.camilodelvasto commentedon Sep 2, 2018
I was getting the error with this line:
When I set it to
true, the error went away. Is that error expected or is it something in my setup? Also, I couldn't find it documented... just leaving it here in case it helps someone, but it seems the error message is indeed misleading.TyroTan commentedon Nov 25, 2018
It's amazing how I also bumped into this but it's because 'model' was misspelled as 'mode'. I thought that it's worthy to mention
mahsan3-zz commentedon Mar 28, 2019
Had the same error message, but it turns out it was because the model I was trying to include had multiple associations to the model I was searching on. Adding an alias to the associations fixed the issue.
davicente commentedon Aug 13, 2019
You made my day man, thanks a lot. This solved my issue ;)
michcio1234 commentedon Dec 30, 2019
I just ran into it because I misspelled
association.This error message really could be a bit more useful. ;/
LWanjiru commentedon Sep 21, 2023
Hope this helps. I was stuck too long trying to figure it out after I got major bugs on a project. Here's the link to how I solved it ==> #11285 (comment)