trailsjs / trailpack-sequelize

:package: Sequelize.js Trailpack http://sequelizejs.com
MIT License
5 stars 9 forks source link

Include only selected attributes from association in query #42

Open JAertgeerts opened 6 years ago

JAertgeerts commented 6 years ago

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 commented 6 years ago

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...