From 9ef353cdf9d328bf2bcf4901be256c4c421d9cb9 Mon Sep 17 00:00:00 2001 From: Peter Retzlaff Date: Fri, 1 Feb 2019 10:40:42 +0100 Subject: [PATCH] Fix group count for DISTINCT queries. --- lib/active_record_group_count/scope.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_record_group_count/scope.rb b/lib/active_record_group_count/scope.rb index 988c71d..7104f67 100644 --- a/lib/active_record_group_count/scope.rb +++ b/lib/active_record_group_count/scope.rb @@ -4,7 +4,7 @@ module Scope module ExtensionMethods def count(*args) - scope = except(:select).select("1") + scope = except(:select).except(:distinct).select("1") scope_sql = if scope.klass.connection.respond_to?(:unprepared_statement) scope.klass.connection.unprepared_statement { scope.to_sql } else