-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Description
What you are doing?
I try to include hasMany association with "include" that uses both "separate" option and "attributes" option
const Parent = sequelize.define('Parent',
{
id: { type: Sequelize.INTEGER, primaryKey: true},
name: { type: Sequelize.STRING(50)}
});
const Child = sequelize.define('Child',
{
id: { type: Sequelize.INTEGER, primaryKey: true},
name: { type: Sequelize.STRING(50)}
});
Parent.hasMany(Child,{as: 'children'});
sequelize.sync({force:true,logging: false})
.then(()=>Parent.create({
id: 1,
name: 'Parent1',
children: [{id: 1,name: 'Child1'},{id: 2,name: 'Child2'}]
},{include: [ {association: 'children'} ]}))
//first, we use an include with only "attributes" option: works fine
.then(()=>Parent.findAll({
include: {
association: 'children',
attributes: ['name']
}}))
//next we use an include with only "separate" option: works fine, too
.then(()=>Parent.findAll({
include: {
association: 'children',
separate: true
}}))
//finally, we try the include with both "separate" and "attributes" options: FAILS
.then(()=>Parent.findAll({
include: {
association: 'children',
attributes: ['name'],
separate: true
}}))What do you expect to happen?
I expect that you can use both options together.
It should be possible to select certain attributes only AND to request separate queries (to avoid the 63 character issue when using PostgreSQL, for example)
What is actually happening?
when using both options together, findAll fails with this error:
Unhandled rejection TypeError: Cannot read property 'push' of undefined
at Model.findAll.then.results (C:\test\constraints\node_modules\Sequelize\lib\associations\has-many.js:230:66)
at tryCatcher (C:\test\constraints\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\test\constraints\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\test\constraints\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\test\constraints\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\test\constraints\node_modules\bluebird\js\release\promise.js:693:18)
at Async._drainQueue (C:\test\constraints\node_modules\bluebird\js\release\async.js:133:16)
at Async._drainQueues (C:\test\constraints\node_modules\bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues (C:\test\constraints\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:651:20)
at tryOnImmediate (timers.js:624:5)
at processImmediate [as _immediateCallback] (timers.js:596:5)
Dialect: postgres
Database version: 9.4
Sequelize version: 4.7.5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels