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

The return value Count of the FindByPage function is always 0. #1116

Open
short-sighted opened this issue Apr 2, 2024 · 0 comments
Open

Comments

@short-sighted
Copy link

short-sighted commented Apr 2, 2024

Your Question

My English is not good, so please forgive me if there are any mistakes in my expression.

Environment:

  • GORM version: v1.25.9
  • Gen version: v0.3.25
  • go-mssqldb version: v1.6.0

The findbypage function generated by GORM returns a count of 0.
I suspect the issue lies in the SQL generated by Gen when calling *.Offset(-1).Limit(-1).Count().
The generated SQL orders by the primary key column, causing an error due to the primary key column not being included in any aggregation function or Group clause.
The generated SQL looks like this: select count(*) from "user" order by "id".
Also I noticed that the generated similar function ScanByPage uses *.Count() directly to return the quantity.

The document you expected this should be explained

Expected answer

Since my current environment only supports SQL Server, I found that temporarily replacing *.Offset(-1).Limit(-1).Count() with *.Count() resolves the issue.
However, I am still interested in understanding why the original SQL is generated and how to address it properly.

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

1 participant