haxetink / tink_sql

SQL embedded into Haxe
MIT License
53 stars 17 forks source link

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

Open cedx opened 10 months ago

cedx commented 10 months ago

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.