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
{{ message }}
Repository navigation
TypeError: Cannot read property 'databaseName' of undefined #4270
I think pagination+ embedded orderBy+ subquery + leftJoinAndSelect combination is giving me the problem.
Reacted by Phillipp Bertram, Li Jhih-Cing, Mojca Rojko, Ben Rogers, Kevin M., Liam McElroy, Giovanni Lela, Theresa, Ruben Arturo Abarca Navarro, Safwan Shaheer and 20 more
#747 might help. OrderBy expects propertyNames instead of column names.
Reacted by Adam Bar, ScriptedAdventure, Mathieu Larose, Allan Pinheiro de Lima, Lam Tung, TBryant, mikematt, Faizan, elvinmezacb, Euichan Kim and 30 more
Reacted by Saman Sajedi, Kevin Huang, ordalbang, Mogeli lortkipanidze, Roberto Souza and Manh Nguyen
Reacted by Mogeli lortkipanidze, Syed Waqas, Roberto Souza, Hitesh Pathak, Adrián Mujica González and Manh Nguyen
Reacted by ordalbang, Mogeli lortkipanidze and Manh Nguyen
Any idea on when/how this will be fixed? I'm also trying to orderBy on a leftJoinAndSelect column.
Reacted by Alex Rudenko, kwanso-nadeem, Stephen Bulsara, Nathan Farkash, ScriptedAdventure, mykyta-manuilenko-axon, Mel, malex410, UnrealCherry and skliarovartem
Reacted by Stephen Bulsara, Daniel Kretsch, jchapelle, Nathan Farkash, ScriptedAdventure, Wahaj Aayani, Omar Diab, Bart, Divyanshu Kalra, Safwan Shaheer and 4 more
Not supporting pagination is a bit of a deal breaker tbh. I like Typeorm but lacking real pagination is a pretty big issue. Been trying to fix this for a while now, to no avail
#747 might help. OrderBy expects propertyNames instead of column names.
Is this in the docs ? I did'nt find this anywhere. I've lost good chunk of hours until I found your answer
To explain why is this important:
I have a second database, not owned by me, which is updated by an automated software ( PACS - medical system ). I have mapped the properties that I use into a local model, so I can take advantage of typeorm, but when I used the query builder, since I changed the aliases of column names on my side, I was not able to order the query.
If this was in docs, it would be great!
I can make a pull request for this, since I'll forget by the end of the week anyways
@Entity({name: 'categories'})
export class Category extends BaseEntity {
@PrimaryGeneratedColumn()
public id: number;
@Column({name: 'my_name'})
public name: string;
}
In QueryBuilder use qb.orderBy('categories.name', filter.orderDirection);
Instead of column name from database. qb.orderBy('categories.my_name', filter.orderDirection);
Reacted by Hendrix Roa, antowkabond, Han.Z, Duy Minh Nguyen, Keita, Sandro, Spencer Pogorzelski, Adrian Pietrzak , wanding, erzegoto and 29 more
Reacted by Maria, Alireza Bonab, Song Yongseok and Manh Nguyen
Reacted by Hendrix Roa, antowkabond, Duy Minh Nguyen, Spencer Pogorzelski, wanding, Norrapat Nimmanee, Maria, Song Yongseok, Ayushi Gandhi, ordalbang and 4 more
Reacted by Duy Minh Nguyen, Spencer Pogorzelski, Mihael, wanding, Norrapat Nimmanee, Maria, Leonardo Ascione, Alireza Bonab, Song Yongseok, Benjamin and 5 more
Reacted by Alireza Bonab, Song Yongseok, José Neto, ordalbang, Mogeli lortkipanidze, Manh Nguyen and Dream Catcher
Adding a further wrinkle here, if I want to order by a complex expression that does not correspond to a specific field, I also get this problem. Ex:
qb.addOrderBy('CASE WHEN (EXTRACT(doy from now())::int-vds.doy) < 0 THEN 366+(EXTRACT(doy from now())::int-vds.doy) ELSE (EXTRACT(doy from now())::int-vds.doy) END', 'ASC');
Where vds is a table (view, actually, but not important here) that I'm joining purely for the ability to sort.
I think you are using getMany() method of typeorm. You shouldn't use like this orderBy('post.category_id'). You shuold use like this orderBy('post.category')
Still happening in 0.3.26. I'm seriously thinking about migrating our bunch of NestJS apps out of typeorm by now. Too many weird issues and workarounds / small hacks applied throughout the years. 2k4 opened issues now and I don't often see the maintainers any where answering these issues these days. How should I not be concerned?
Activity
vlapo commentedon Jun 12, 2019
This should be fixed in
@nextbranch. It is possible for you to usetypeorm@next?v1d3rm3 commentedon Jun 12, 2019
@next commits are far behind from master. @next will be 0.3.0?
vlapo commentedon Jun 12, 2019
Yes
@nextis branch for 0.3.0. This branch contains breaking changes not included in current master branch.v1d3rm3 commentedon Jun 13, 2019
We've a lot of code in 0.2.x. The lack of documentation of @next could be a problem too. =/
tizzyapunkt commentedon Oct 29, 2019
#747 might help. OrderBy expects propertyNames instead of column names.
LoicMahieu commentedon Dec 10, 2019
I found a fix for the
masterbranch, inspired by next:God I beg your pardon 🤫
highflying commentedon Feb 11, 2020
Any idea on when/how this will be fixed? I'm also trying to orderBy on a leftJoinAndSelect column.
kwanso-nadeem commentedon Mar 5, 2020
Waiting for a fix here.
sinclairnick commentedon Apr 3, 2020
Not supporting pagination is a bit of a deal breaker tbh. I like Typeorm but lacking real pagination is a pretty big issue. Been trying to fix this for a while now, to no avail
aayani commentedon Apr 5, 2020
Getting the same error while trying this combination with Postgres behind.
Can try raw query for now.
btd1337 commentedon Jun 26, 2020
Check if your query params are correct. Here my ordering query was with an incorrect property name in
sortand then this error was reported.Fixing it, all works properly:
AllanPinheiroDeLima commentedon Aug 12, 2020
Is this in the docs ? I did'nt find this anywhere. I've lost good chunk of hours until I found your answer
To explain why is this important:
If this was in docs, it would be great!
I can make a pull request for this, since I'll forget by the end of the week anyways
Now, my query is working as intended
antowkabond commentedon Oct 27, 2020
I have the same issues.
As for me, it helps
In QueryBuilder use
qb.orderBy('categories.name', filter.orderDirection);Instead of column name from database.
qb.orderBy('categories.my_name', filter.orderDirection);21 remaining items
alxestevam commentedon Feb 23, 2023
@wladimirguerra I think this should work:
andrey010 commentedon Apr 25, 2023
Also had this error . My solution set take, skip to limit, offset
RodriguesGabrielTi commentedon Aug 14, 2023
@andrey010 limit and offset can not work properly when used join on the same query:

fatahnuram commentedon Sep 3, 2023
waiting for a fix here..
pvogel1967 commentedon Oct 27, 2023
Adding a further wrinkle here, if I want to order by a complex expression that does not correspond to a specific field, I also get this problem. Ex:
Where vds is a table (view, actually, but not important here) that I'm joining purely for the ability to sort.
hitesh-pathak commentedon Nov 17, 2023
Worked for me, thanks a ton!
shaxi007 commentedon Jan 31, 2024
I think you are using getMany() method of typeorm. You shouldn't use like this orderBy('post.category_id'). You shuold use like this orderBy('post.category')
fix(resource): pagination with filters and ordering
dattran1232003 commentedon Jul 27, 2025
Wow, 2025, and this is still correct, super!
hungluu commentedon Sep 13, 2025
Still happening in
0.3.26. I'm seriously thinking about migrating our bunch of NestJS apps out of typeorm by now. Too many weird issues and workarounds / small hacks applied throughout the years. 2k4 opened issues now and I don't often see the maintainers any where answering these issues these days. How should I not be concerned?RaederDev commentedon Jan 12, 2026
Still an issue also with postgresql. I had to add some ugly workarounds to bypass this. Is there a plan to fix this?
gioboa commentedon Jan 13, 2026
Can you try the preview package of this PR please?
RaederDev commentedon Jan 13, 2026
@gioboa thanks! I can confirm this patch fixes the issue