mysql - How to order by an aggregate function in sequelize -


i feel if i've hit brick wall while converting old php app functionality on node , sequelize. maybe i'm approaching limits of orm can do, want ask before give up.

let's imagine 3 tables: video, task, publishdate.

the application requires video may have multiple publishdates , multiple tasks. tasks have due dates calculated looking @ minimum of video's publishdates.

so if video has 2 publishdates of 2015-12-01 , 2015-08-15, we'd use 2015-08-15 , perform additional calculations on task due date.

the problem occurs when i'm trying list of tasks ordered calculated due dates.

i've attempted many different approaches. latest try attempts use sequelize.fn function

models.task.findall({   where: {isactive: false, iscompleted: false},     include: [       {         model: models.video,          attributes: [[sequelize.fn('min', 'video.publishdates.date'), 'duedate']],         include: [models.publishdate]       }     ],   order: [['video', 'duedate', 'asc']],   limit: 50 }) 

i'm not encouraged i'm headed in right direction because without order clause, attempt returns 1 record. still, feels closest i've been day , i'm missing bit of information or syntax make possible.

this first foray world of orms, apologize if there simple i'm missing. tried best looking documentation , other questions on google no luck far.

you need order using function. should try:

order : [['video','asc'],[sequelize.fn('min', 'video.publishdates.date'), 'asc]] 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -