pirate pirate - 11 months ago 115
Node.js Question

Order by in nested eager loading in sequelize not working

i have four model Tehsil, Ilr, Patwar, and Villages.
and their association is

Tehsil -> 1:m -> Ilr -> 1:m -> Patwar -> 1:m -> Villages

i want to to apply order by on all four of my models.


var tehsilQuery = {
include: [{
model: Ilr,
as: 'GirdawariKanoongo',
include: [{
model: Patwar,
as: 'GirdawariPatwar',
include: [{
model: Villages,
as: 'GirdawariVillages',
order: [
['tehsil_name', 'ASC'],
[ {model: Ilr, as: 'GirdawariKanoongo'}, 'kanoongo_name', 'ASC'],
[ {model: Patwar, as: 'GirdawariPatwar'}, 'patwar_area', 'ASC'],
[ {model: Villages, as: 'GirdawariVillages'}, 'village_name', 'ASC'],
return Tehsils.findAll(tehsilQuery);

[Error: 'girdawari_patwar' in order / group clause is not valid association]

order by is working if i remove
(lat two model) from

Answer Source

i solved it. here's how order looks:

order: [

all i have to do is: using the as in association of table and chaining them followed by column_name on which order supposed to apply.