You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by bolav, webolizzer, musicformellons, Bosn, Vladyslav Huba, Brad Isbell, Oscar Jovanny García Zepeda, Klendi Goci, mvdelt, Christian Schuff and 43 more
Reacted by Klendi Goci, Danang Balany, Victor Copque and Jboucly
Reacted by Puria Rad Jahanbani, Klendi Goci, Yuri Luiz de Oliveira, Victor Copque, Viacheslav Okhmak, Chandima Gunawardhana, rmadi, Faouzi Mohamed, kggm9408 and Ergashbek Matkarimov
That syntax is not currently supported (except with separate: true which only works for hasMany atm).
You need to use the slighter longer/sweird syntax:
Reacted by bolav, bruntha1991, Gijo Varghese, CMYK, Thomas Ebert, Oleksii Shovhenia, Michael DePetrillo, Ricardo Montes, Dace, Alexey and 134 more
Reacted by Rabia Asif, Cuongctk39, Arif Setyo Nugroho, Shehryar Shoukat, Andy, Ryan Tian, Michael Yaworski and Manuchehr
Reacted by Victor Copque, Danilo Lacerda , Andy and Rafael
Reacted by Brad Isbell, Thomson P, Saurabh Mistry, Amaury Rousseau, caillef, Shehryar Shoukat, Victor Copque, Pablo Lopes, uassawa, xSefx and 2 more
Reacted by Puria Rad Jahanbani, Saurabh Mistry, Amaury Rousseau, Aleksandr Uspenskyi, Talal Najam, Shehryar Shoukat, Victor Copque, Ilia Baikov, Sushmitha B S, Kamil and 11 more
Reacted by Victor Copque, Álvaro Agüero, Pablo Lopes, DmitriiBo, Rafael, shahnawaz114, Marcus Lima, Пүрэвжаргал and Colin-JC
Thanks for a quick reply :) Unfortunately this syntax is not working for me, it throws:
Unhandled rejection Error: 'images' in order / group clause is not valid association
at Object.QueryGenerator.quote (/home/robert/your-priorities-app/node_modules/sequelize/lib/dialects/abstract/query-generator.js:801:17)
Reacted by km, Philippe Auriach, Sasha Kalmikov, Ruifeng Ma, Jozef Cipa, Sarang N, Rafael and skallonis
Ah yes if you have an alias on your incldue you'll need to use [{ model: models.Image, as: 'IdeaHeaderImages' }, 'updated_at', 'asc']
Reacted by Anoop Varghese, Kris Kaczor, Yueyang Chen, km, Alex Y, Dylan Cutler, CMYK, Nick Clyde, Cameron Morrison, Philippe Auriach and 80 more
Reacted by Manuchehr
Reacted by Senthil, xinyu, ayoe, Pablo Lopes, Ankit Maurya, Roger Padilla and Muhammad
Reacted by Sébastien Lemeur, Anthony DOWTK, Pedro Mapelli, Ruifeng Ma, mb8z, xinyu, Joel Worsham, Ankit Maurya, Roger Padilla, Guillaume Hachez and 4 more
Reacted by Norman Murillo, yotinny, Bankbetch, Joel Worsham and Denis Gutsuliak
How would one use an aliased nested model?
e.g. if I would want to order by an attribute from a model which is associated withmodels.Image from this example (one more nesting level).
Reacted by Yueyang Chen, elasticsearcher, webolizzer, zhao5363, manoylo, Igor Yakutovich, Pijus Vaskevicius, musicformellons, Lorenzo Pietrangeli, Jerome S. and 56 more
Reacted by João Paulo
Reacted by Manoel Ribeiro, Fernando de Paula F. Maciel, Roger Padilla, Ayoub Laazazi, Lucas Almeida, Shelby Reyes, João Paulo and akmozo
Reacted by Lucas Lima Fonseca, Fernando de Paula F. Maciel, Gigih Iski Prasetyawan, Roger Padilla, Ayoub Laazazi, Lucas Almeida, Julfikar Haidar, Shelby Reyes, João Paulo, akmozo and 3 more
Reacted by José Silva Jr., Fernando de Paula F. Maciel, Winadi Wiratama, Roger Padilla, Ayoub Laazazi, Baris Ozdemirci, Lucas Almeida, Serdar, Shelby Reyes, João Paulo and 1 more
I am trying something like this: order:[ { model: this.associations['profile_status'].target}, 'updatedAt', 'DESC' ], but i am getting an error as error: NaNTypeError: Converting circular structure to JSON
Hi there
in my case "User" has many "MBTI Test" and I want to order results by "created_at" of "MBTI Test".
here is my code but the order is not working.
Reacted by Phil Greenberg, Guillaume Olejniczak, Niki Ahlskog, vishalnarewade, Roberth Pereira, João Paulo Nespolo, Boogie-Yan, Suhail Akhtar, deep , Luis Antonio Canettoli Ordoñez and 10 more
Reacted by eassymo, MD Ariful Islam, Rabia Asif, Duong Ngo, scottmay2020, Marcelo Peralta, Tibor Otott-Kovacs and Sarang N
Reacted by Matheus Mendes and Muktadir Hassan
Reacted by Matheus Mendes, Muktadir Hassan and Nahid Iftekhar
Reacted by Bradley, Dave W., Sergey Peshkov, Yuri Fontella, David MacGugan, Eric Kerr, Krisan Timur, Nghĩa, Ben Watts, Krisna Margono and 211 more
Reacted by Blake Miner, Olusegun Adesanya, Tiago Gouvêa, Arnaud Doucerain, Devendra Tiwari, Vedran Karačić, Ilia Sidorenko, Dali, troimendoza, MD Ariful Islam and 27 more
Reacted by Olusegun Adesanya, Tiago Gouvêa, Andreas Titan, Aviran, Vedran Karačić, Ilia Sidorenko, MD Ariful Islam, Leo Doldan, Nicholas Stephenson, Viacheslav Okhmak and 10 more
Reacted by Olusegun Adesanya, Tiago Gouvêa, Richard Lewis, Özer Cevikaslan, Ilia Sidorenko, Leo Doldan, Salathiel Genese, Nicholas Stephenson, Lina, Viacheslav Okhmak and 5 more
Reacted by Olusegun Adesanya, NV4RE, musicformellons, Tiago Gouvêa, Thomas Victoria, marjev, Ilia Sidorenko, MD Ariful Islam, Leo Doldan, Ahmed Amine RASSAS and 8 more
Reacted by Jay Ellos, William Evieux, linfeng, Lary, Lieu Nguyen and Muhammad Irvan Hermawan
Reacted by kwanso-nadeem, William Evieux, damon and linfeng
how about direct only order in order paramter in outside of include ? looks like where query using $
for example $table.table.column$ . its only work in where query but in order its not work to order by.
my expectede is order by table name and column , not models name.
order: [['form_hulu_miga.dm_river_boat_hm.id', `DESC`]] // the error, TypeError: Cannot read property 'type' of undefined // i use hard code here not with variable
For those who are still getting an error such as 'Unknown column in order clause':
Add subquery: false as in the top level of the options object.
The problem being if you set a LIMIT, that value defaults to true and uses a subquery to recreate the table so your included columns are not in scope.
Activity
mickhansen commentedon Sep 21, 2015
That syntax is not currently supported (except with
separate: truewhich only works for hasMany atm).You need to use the slighter longer/sweird syntax:
rbjarnason commentedon Sep 22, 2015
Thanks for a quick reply :) Unfortunately this syntax is not working for me, it throws:
rbjarnason commentedon Sep 22, 2015
Seems to be connected to the models.Image using an as: in the include:
Using your suggested method works with other models than Image that don't use the as:
mickhansen commentedon Sep 22, 2015
Ah yes if you have an alias on your incldue you'll need to use
[{ model: models.Image, as: 'IdeaHeaderImages' }, 'updated_at', 'asc']rbjarnason commentedon Sep 22, 2015
Thanks! That worked 👍
oleiba commentedon Apr 24, 2016
How would one use an aliased nested model?
e.g. if I would want to order by an attribute from a model which is associated with
models.Imagefrom this example (one more nesting level).rbjarnason commentedon Apr 24, 2016
It's easy, just add the nested chain in the inner order array, here are two levels:
Here are 3 levels:
oleiba commentedon Apr 24, 2016
Thanks! Worked for me!
dilip489 commentedon Jun 22, 2016
I am trying something like this:
order:[ { model: this.associations['profile_status'].target}, 'updatedAt', 'DESC' ], but i am getting an error as error: NaNTypeError: Converting circular structure to JSONharoldkyle commentedon Apr 21, 2017
@dilip489 I was having this same problem because the
orderproperty needs to be in another array. In your example:jsina commentedon Sep 3, 2017
Hi there
in my case "User" has many "MBTI Test" and I want to order results by "created_at" of "MBTI Test".
here is my code but the order is not working.
cbaron commentedon Nov 1, 2017
@jsina, you need to do:
philberg commentedon Nov 21, 2017
@cbaron thank you! I've been trying to chase this down for awhile now and none of the docs or tests explain how to do this correctly in v4.
cbaron commentedon Nov 21, 2017
Yeah, the docs are really bad.
45 remaining items
bobpepers commentedon Jun 10, 2022
were you able to solve this? i'm trying something simular where i want order based on the sum of an included association
farzanmanafi commentedon Jun 10, 2022
AnkurBansal18 commentedon Jun 21, 2022
order: [
[{ model: Image, as: "IdeaHeaderImages" }, "updated_at", "DESC"],
],
try this, it worked for me.
ismail-arshad-codegenio commentedon Jul 22, 2022
find any solution?
ashadul-mridha commentedon Sep 21, 2022
if anyone still needs this as I did, using separate true you can do things like this
its work for me at 2022
include: { model: OtherModel, separate: true, order: [ ['createdAt', 'DESC'] ] }
yogithesymbian commentedon Nov 18, 2022
how about direct only order in order paramter in outside of include ? looks like where query using
$for example
$table.table.column$. its only work in where query but in order its not work to order by.my expectede is order by table name and column , not models name.
yogithesymbian commentedon Nov 18, 2022
my problem is
the output of raw query the order by not use
', how i can put the'in order by ?the above code output sql is ( unExpected )
what i expected is
yogithesymbian commentedon Nov 18, 2022
now its work by
jhawkins11 commentedon Jun 14, 2023
For those who are still getting an error such as 'Unknown column in order clause':
Add
subquery: falseas in the top level of the options object.The problem being if you set a LIMIT, that value defaults to true and uses a subquery to recreate the table so your included columns are not in scope.
james-skills commentedon Dec 26, 2024
How can we handle the case if the top statement is findByPk instead of findAll?
Actually,
I'd like to sort TotalSummary out but it remains as they are.
LeonxLJX commentedon Sep 2, 2026