Found a fringe case bug and made a patch:
When calling #count on a model and passing a :select value with
DISTINCT in, and eager loading an association, ActiveRecord blindly
adds another DISTINCT to the COUNT parameter.
Example (based on ActiveRecord test cases)
Account.count( :select => 'DISTINCT accounts.id', :include => :firm )
Produces the following invalid SQL
SELECT count(DISTINCT DISTINCT accounts.id) AS
count_distinct_accounts_id FROM `accounts` LEFT OUTER JOIN
`companies` ON `companies`.id = `accounts`.firm_id AND
`companies`.`type` = 'Firm'
The fix is trivial, and all tests pass in the same fashion as before
the patch. Hope its accepted quickly...
This was tested with MySQL, discovered by chance while debugging the