I am trying to write a hook which adds ordering to a query on a table with associations. My query is on 'points' which has a join-table 'point_photos' and then is associated m:n to 'photos'. The standard feathersjs $sort can not be used for associated sorting, so I tried to set sequelize 'order' in a hook and this works splendidly. Now I would like to set the 'order' from a find query:
return app.service('points').find(
{
query: {
point_id: [1, 2, 5],
include: ['PointPhotos'],
order: [
[
'point_id',
'DESC'
],
[
'PointPhotos',
'photo_id',
'DESC'
]
]
}
}
);
})
But now I get:
error: SequelizeDatabaseError: column points.order does not exist
Which is odd to me as hook.params.sequelize looks the same to me for the hook and the query...
Also when I simplify the find query 'order' I get the same error; is adding 'order' to the query object not allowed?
EDIT: I managed to hack around it by adding the order to the 'include' option:
return app.service('points').find(
{
query: {
point_id: [1, 2, 5],
include: { include: ['PointPhotos'], order: [
[
'point_id',
'DESC'
],
[
'PointPhotos',
'photo_id',
'DESC'
]
]
}
}
}
);
})
And adapting my association hook accordingly. This is a bit silly though as in sequelize 'order' is at the same level as 'include', so it confuses things. My question still boils down to: Why does the 'order' key in the query object not work? It looks like it is considered a table-field somehow.