javascript - Sequelize include model attributes not working -
i need select 2 instances same model eager loading fields need, attributes
property not working on include objects
db.company.findall({ where: { industry: stock.industry }, attributes:['id'], include:[{ model: db.price, as: 'lastprice', attributes:['adjclose'], limit: 1, order: '"createdat" desc' }, { model: db.price, as: 'comparisonprice', attributes:['adjclose'], where:{ createdat:{ $lte: comparisondate, $gte: limitdate } }, limit: 1, order: '"createdat" desc' }] })
since need different instances same model associations are
company.hasmany(models.price,{ as: 'lastprice', foreignkey:"companyid" }); company.hasmany(models.price,{ as: 'comparisonprice', foreignkey:"companyid" });
and got error
typeerror: cannot read property 'push' of undefined @ c:\users\arhov\documents\projects\finstead\node_modules\sequelize\lib\associations\has-many.js:331:64 @ array.foreach (native) @ .<anonymous> (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\lib\associations\has-many.js:330:13) @ trycatcher (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\util.js:16:23) @ promise._settlepromisefromhandler (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:510:31) @ promise._settlepromise (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:567:18) @ promise._settlepromise0 (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:612:10) @ promise._settlepromises (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:691:18) @ async._drainqueue (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\async.js:138:16) @ async._drainqueues (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\async.js:148:10) @ immediate.async.drainqueues (c:\users\arhov\documents\projects\finstead\node_modules\sequelize\node_modules\bluebird\js\release\async.js:17:14) @ runcallback (timers.js:570:20) @ tryonimmediate (timers.js:550:5) @ processimmediate [as _immediatecallback] (timers.js:529:5)
what wrong code , how should retrieve columns need.
Comments
Post a Comment