Skip to content

Include only selected attributes from association in query #42

Open
@JAertgeerts

Description

@JAertgeerts

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions