I am running into an issue where I get an error message, Unhandled rejection TypeError: Cannot read property \'getTableName\' of undefined
when I try to associa
You need to rewrite your query to look like:
models.DiscoverySource.findAll({
attributes: ['discoverySource'],
where: {
organizationId: req.user.organizationId
},
include: [{
model: models.Organization,
attributes: ['organizationName', 'admin']
}]
})
According to the Sequelize documentation:
[options.attributes] - A list of the attributes that you want to select, or an object with include and exclude keys.
[options.include[].attributes] - A list of attributes to select from the child model.
[options.include[].through.where] - Filter on the join model for belongsToMany relations.
[options.include[].through.attributes] - A list of attributes to select from the join model for belongsToMany relations.
So, [options.include[].through]
can only be used in case of Belongs-To-Many
association rather than Belong-To
used by you for DiscoverySource
and Organization
models.