Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include only selected attributes from association in query #42

Open
JAertgeerts opened this issue Dec 31, 2017 · 1 comment
Open

Include only selected attributes from association in query #42

JAertgeerts opened this issue Dec 31, 2017 · 1 comment

Comments

@JAertgeerts
Copy link
Contributor

JAertgeerts commented Dec 31, 2017

Works as expected, this includes all fields from association + id attribute from organisation:

this.app.orm.Organisation.findAll({
          include: ['User'],
          attributes: ['id']
})

Does not work:

this.app.orm.Organisation.findAll({
          include: [{
            attributes: ['id'],
            model: 'User',
            through: {
              attributes: ['name']
            }
         }]
})

Error:

Unhandled rejection TypeError: self._expandAttributes is not a function
    at Function._conformOptions (/node_modules/sequelize/lib/model.js:189:12)
    at Function._conformInclude (/node_modules/sequelize/lib/model.js:255:12)
    at options.include.options.include.map.include (/node_modules/sequelize/lib/model.js:204:59)
    at Array.map (<anonymous>)
    at Function._conformOptions (/node_modules/sequelize/lib/model.js:204:39)
    at Promise.try.then (/node_modules/sequelize/lib/model.js:1504:12)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at tryCatcher (/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

This means I can't select only 1 attribute of an association.

Outside of trails, both scenarios work as expected.

@jaumard
Copy link
Contributor

jaumard commented Apr 6, 2018

Do you use exactly the same version of sequelize when you test outside of Trails ? Because everything that is inside this.app.orm is fully native sequelize so strange that is failing only under Trails...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants