typeorm: TypeError: Cannot read property 'databaseName' of undefined
Issue type: [x] bug report
Database system/driver:
[x] mssql
TypeORM version:
[x] latest
Steps to reproduce or a small repository showing the problem:
Here is a repo with the bug: https://github.com/victorschinaider/typeorm-bug
I think pagination+ embedded orderBy+ subquery + leftJoinAndSelect combination is giving me the problem.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 25
- Comments: 39 (4 by maintainers)
Commits related to this issue
- Update typeorm-crud.service.ts fix this issue: https://github.com/typeorm/typeorm/issues/4270#issue-454634846 — committed to Darkein/crud by Darkein 2 years ago
- fix(resource): pagination with filters and ordering https://github.com/typeorm/typeorm/issues/4270 — committed to cisstech/platon by mciissee 5 months ago
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);So, I just replaced
takewithlimitand it works for me.#747 might help. OrderBy expects propertyNames instead of column names.
Waiting for a fix here.
if join、orderBy、take、skip are used together, the problem that
Cannot read property 'databaseName' of undefinedwould happen.there are two solutions. one could be found in the comment of this issue: https://github.com/typeorm/typeorm/issues/4270#issuecomment-987799139
anther solution as follows: use camel-case type instead of snake-case type in orderBy. for example, made a page query using orderBy of
a.create_timewhich defined in the table, the orderBy here would be replaced with.orderBy('a.createTime', 'DESC').Getting the same error while trying this combination with Postgres behind.
Can try raw query for now.
Any idea on when/how this will be fixed? I’m also trying to orderBy on a leftJoinAndSelect column.
Wtf?
I just spent hours trying to debug this. For me, makes no sense.
I got the same error when there were two columns listed in the orderBy - which works fine when used with
limit, but fails when used withtake.Removing one of the columns made it work.
I agree, this is a very useless (and incorrect) error message. I also find the pagination documentation lacking, as it says:
but it does not elaborate on what these functions are doing that’s so special.
Also had this error . My solution set take, skip to limit, offset
@wladimirguerra I think this should work:
This is a terrible error message. For me the issue was that the sort/orderby column was incorrect (didn’t exist - copy/pasta).
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:
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
It’s not great when a single method change, in my case limit() -> take(), can blow up your entire app in such a misleading way…
But I can confirm using entity property names instead of column names in the orderBy clause in a query with a join worked.
I found that replacing
take(1).getOne()withgetOne()fixed this (and probably I should have made that change anyway).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’)
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 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