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

Unable to use an aggregated value in orderBy() #155

Open
cedx opened this issue Dec 4, 2023 · 0 comments
Open

Unable to use an aggregated value in orderBy() #155

cedx opened this issue Dec 4, 2023 · 0 comments

Comments

@cedx
Copy link
Member

cedx commented Dec 4, 2023

In this kind of query:

import tink.sql.expr.Functions;

return db.picture
  .leftJoin(db.vote).on(vote.pictureId == picture.id)
  .select({createdAt: picture.createdAt, id: picture.id, voteCount: Functions.count(vote.id)})
  .groupBy(row -> [row.picture.id])
  .orderBy(row -> [{field: row.voteCount, order: Desc}]) // Error: <type> has no field voteCount.
  .all();
  .next(rows -> trace(rows.map(row -> row.voteCount)); // OK.

In the next() call, I can access the aggregated value (i.e. voteCount), but I can't use it in the orderBy() clause.

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