TypeError: Cannot read property 'getTableName' of undefined

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

18reactions
trevorh2007commented, Mar 14, 2018

To add on to this I ran into this similar situation. Same error, same console logging results. My issue was

include: [{
    model: Scholarship,
    as: 'scholarships',
    required: false,
    through: {
        attributes: []
    }
}]

that there was no join table that ‘through’ could use, so just getting rid of ‘through’ like this:

include: [{
    model: Scholarship,
    as: 'scholarships',
    required: false
}]

Solved my issue

11reactions
KieronWiltshirecommented, Jun 18, 2016

Solved

The issue was that I was passing ‘include’ through as an object and not an array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Sequelize Association Error Cannot read property ...
I am running into an issue where I get an error message, Unhandled rejection TypeError: Cannot read property 'getTableName' of undefined ...
Read more >
cannot read properties of undefined (reading 'gettablename')
Viewed 5k times 1 I am running into an issue where I am trying to associate two models that have a one-to-many relationship....
Read more >
Node.js – Sequelize Association Error Cannot read ... - iTecNote
I am running into an issue where I get an error message, Unhandled rejection TypeError: Cannot read property 'getTableName' of undefined when I...
Read more >
TypeError: Cannot read property 'getTableName' of undefined
belongsToMany: TypeError: Cannot read property 'getTableName' of undefined. graphql-sequelize. 19 December 2016 Posted by Guten Ye.
Read more >
ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE ! ... Your browser can't play this video. ... Solved: ERROR TypeError : Cannot read property title of...
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