• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

1.1K
Views
TypeORM querybuilder with take,skip and order by

I have an issue with a NestJs service that uses Typeorm and implements pagination logic.

When I use limit and offset on a query I execute using QueryBuilder, it does not return all results (i.e. limit 10 returns only 8 results)- it does work however, meaning that the relations aren't mapped yet still filtered on, orderby does order by a relation field without mapping it too. The issue began when I changed my limit and offset to take and skip.

It gets buggy when I use order by on a relation column I innerJoin.

For example:

querybuilder = querybuilder.innerJoin(profile.service, service)

then try to do

 queryBuilder = queryBuilder.orderBy("service.price", "ASC")

It returns an error

column distinctAlias.service_price does not exist

That's because it looks like you must leftJoinAndSelect the relation in order to have the field alias included in the query.

I don't want to select the relations but only the base entity. Is there any way around it?

Limit and offset as pagination utilities are not an option since in the docs itself it says to not use them when appending joins to the query.

about 3 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error