From 0aae7806c10e3e3cce671c23dac6a8958ba89629 Mon Sep 17 00:00:00 2001 From: Maxime Lapointe Date: Wed, 10 Aug 2016 17:27:32 -0400 Subject: Fix count which would sometimes force a DISTINCT The current behaviour of checking if there is a LEFT OUTER JOIN arel node to detect if we are doing eager_loading is wrong. This problem wasn't frequent before as only some pretty specific cases would add a LEFT OUTER JOIN arel node. However, the recent new feature left_outer_joins also add this node and made this problem happen frequently. Since in the perform_calculation function, we don't have access to eager_loading information, I had to extract the logic for the distinct out to the calculate method. As I was in the file for left_outer_join tests, I fixed a few that had bugs and I replaced some that were really weak with something that will catch more issues. In relation tests, the first test I changed would have failed if it had validated the hash returned by count instead of just checking how many pairs were in it. This is because this merge of join currently transforms the join node into an outer join node, which then made count do a distinct. So before this change, the return was {1=>1, 4=>1, 5=>1}. --- activerecord/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/CHANGELOG.md') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index bf81c23036..6b996fd6bd 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Doing count on relations that contain LEFT OUTER JOIN Arel node no longer + force a DISTINCT. This solves issues when using count after a left_joins. + + *Maxime Handfield Lapointe* + * RecordNotFound raised by association.find exposes `id`, `primary_key` and `model` methods to be consistent with RecordNotFound raised by Record.find. -- cgit v1.2.3