Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: sort by subquery results in error that tableAlias.column does not exists #909

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MohdAhmad1
Copy link

@MohdAhmad1 MohdAhmad1 commented Apr 29, 2024

This pull request addresses issues related to sorting within a column that is created by a subquery

example

   // service.ts
	 const builder = this.pomBoxRepository.createQueryBuilder("pb");

	// subquery
    builder
      .addSelect((subQuery) => {
        return subQuery
          .select("COUNT(t.id)", "trayCount")
          .from(Tray, "t")
          .where("t.pom_box_name = pb.name");
      }, "trayCount")

	 return paginate(query, builder, {
       sortableColumns: ["trayCount" as any],
    });

this service results an error from db Unknown column 'pb.trayCount' in 'order clause'.
This PR fixes above problem

@Helveg
Copy link
Collaborator

Helveg commented Apr 30, 2024

Hi! Thanks for your contribution! Could you add a test that shows that this PR fixes the problem you speak of? :)

Copy link
Owner

@ppetzold ppetzold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment from @Helveg

Hi! Thanks for your contribution! Could you add a test that shows that this PR fixes the problem you speak of? :)

If you have showcased / covered the bug in a test, I am happily merging your PR 👋

EDIT: CI is failing due to format. Run npm run format to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants