diff options
author | Rafael Sales <rafaelcds@gmail.com> | 2015-10-12 23:18:51 -0300 |
---|---|---|
committer | Rafael Sales <rafaelcds@gmail.com> | 2015-10-22 04:22:57 -0300 |
commit | c2d33c4abf01ec25b2d1528a7dae923aef5a30af (patch) | |
tree | 309b3035ad66d0e62467ceeecfd0d9d3061df10a /activerecord/lib/active_record/associations | |
parent | d8b076c90efac796e8664c6eada8d08afac4bea3 (diff) | |
download | rails-c2d33c4abf01ec25b2d1528a7dae923aef5a30af.tar.gz rails-c2d33c4abf01ec25b2d1528a7dae923aef5a30af.tar.bz2 rails-c2d33c4abf01ec25b2d1528a7dae923aef5a30af.zip |
Fix generated projection fields in group by query
Closes #21922
Let `Book(id, author_id)`, `Photo(id, book_id, author_id)` and `Author(id)`
Running `Book.group(:author_id).joins(:photos).count` will produce:
* Rails 4.2 - conflicts `author_id` in both projection and group by:
```sql
SELECT COUNT(*) AS count_all, author_id AS author_id
FROM "books" INNER JOIN "photos" ON "photos"."book_id" = "books"."id"
GROUP BY author_id
```
* Master (9d02a25) - conflicts `author_id` only in projection:
```sql
SELECT COUNT(*) AS count_all, author_id AS author_id
FROM "books" INNER JOIN "photos" ON "photos"."book_id" = "books"."id"
GROUP BY "books"."author_id"
```
* With this fix:
```sql
SELECT COUNT(*) AS count_all, "books"."author_id" AS books_author_id
FROM "books" INNER JOIN "photos" ON "photos"."book_id" = "books"."id"
GROUP BY "books"."author_id"
```
Diffstat (limited to 'activerecord/lib/active_record/associations')
0 files changed, 0 insertions, 0 deletions