Skip to content

Commit

Permalink
docs: fix raw query (#5845)
Browse files Browse the repository at this point in the history
The code examples assume many results (see a comment below in each example), but queries were filtered by user.id. Instead groupBy clausule should be used in order to select user.id after using aggregation function.
  • Loading branch information
stefan-malcek committed Apr 13, 2020
1 parent aa28e2b commit e92c743
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/select-query-builder.md
Expand Up @@ -204,7 +204,7 @@ const photosSums = await getRepository(User)
.createQueryBuilder("user")
.select("user.id")
.addSelect("SUM(user.photosCount)", "sum")
.where("user.id = :id", { id: 1 })
.groupBy("user.id")
.getRawMany();

// result will be like this: [{ id: 1, sum: 25 }, { id: 2, sum: 13 }, ...]
Expand Down Expand Up @@ -776,7 +776,7 @@ const photosSums = await getRepository(User)
.createQueryBuilder("user")
.select("user.id")
.addSelect("SUM(user.photosCount)", "sum")
.where("user.id = :id", { id: 1 })
.groupBy("user.id")
.getRawMany();

// result will be like this: [{ id: 1, sum: 25 }, { id: 2, sum: 13 }, ...]
Expand Down

0 comments on commit e92c743

Please sign in to comment.