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

paginateRaw enforcing groupBy when it is not needed #666

Open
GhettoBurger996 opened this issue Jan 8, 2022 · 1 comment
Open

paginateRaw enforcing groupBy when it is not needed #666

GhettoBurger996 opened this issue Jan 8, 2022 · 1 comment

Comments

@GhettoBurger996
Copy link

GhettoBurger996 commented Jan 8, 2022

I have the following query I would like to get the facilities along with the AVG review of each when done like this WITHOUT the pagianteRaw or pagiante function it return the results as expected.

const facilities = await this.connection
        .getRepository(Facility)
        .createQueryBuilder("facilities")
        .select(["facilities.facilityUuid"])
        .leftJoin("facilities.facilityPrice", "fcp")
        .leftJoin("facilities.reviews", "facreviews")
        .addSelect([
          "fcp.facilityPriceUuid",
          `AVG(facreviews.rating) AS "averageRating"`,
        ])
        .groupBy("facilities.facilityUuid")
        .addGroupBy("fcp.facilityPriceUuid")
        .getRawMany();

      return facilities;

The body ends up looking like so,

    {
        "facilities_facilityUuid": "5d996b76-e2ba-4c24-b5c2-bdc53f8f3d4d",
        "fcp_facilityPriceUuid": "5d996b76-e2ba-4c24-b5c2-bdc53f8f3d4d",
        "averageRating": 3.57
    }

The issue is when using the same query and passing it into the paginateRaw or paginate function. It returns the following error. It expects an extra query like so .addGroupBy("facreviews.reviewUuid")


query failed: SELECT COUNT(*) AS "value" FROM (SELECT * FROM "facilities" "facilities" LEFT JOIN "facility_price" "fcp" ON "fcp"."facilityPriceUuid"="facilities"."facilityUuid"  LEFT JOIN "reviews" "facreviews" ON "facreviews"."facilityUuid"="facilities"."facilityUuid" GROUP BY "facilities"."facilityUuid", "fcp"."facilityPriceUuid") "uniqueTableAlias"
error: error: column "facreviews.reviewUuid" must appear in the GROUP BY clause or be used in an aggregate function

I cant group by review, since if I do it will return all the reviews posted, and instead of a single facility with its average review it ends up getting a dozen of entries. Again typeorm performs as intended despite it not being grouped by reviews.

@osmanyz
Copy link

osmanyz commented Apr 12, 2024

This has been open since January 2022 and there is no solution for this?

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

No branches or pull requests

2 participants