nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 534 forks source link

Unable to paginate on typeorm 'view' entity #610

Closed yashwanthl closed 3 years ago

yashwanthl commented 3 years ago

I have created a typeorm 'view' entity based on "https://typeorm.io/#/view-entities". And I am trying to apply nestjs crud on it. I want only getManyBase route. The route works well. But when I set alwaysPaginate as true in 'query' filter the end point returns 500, Internal server error.

When paginate is set as true I see there are two queries being executed

  1. To fetch records from view with offset and limit
  2. To get Distinct Count of records from the view

First query is good but there is an issue with second query. Second query looks like this SELECT COUNT(DISTINCT()) as "cnt" FROM "foo_view" "FooView"

The DISTINCT() method in COUNT has no parameters. That's where the error is. It should ideally contain 'id' and should look something like this SELECT COUNT(DISTINCT(FooView.id)) as "cnt" FROM "foo_view" "FooView" to work

I am using MSSQL database and pagination is working well with all other normal entities

yashwanthl commented 3 years ago

Make sure to have a @PrimaryColumn() in View Entity. That should only be a @PrimaryColumn() NOT combination of @PrimaryColumn() and @ViewColumn()