PATCH: #11502, double DISTINCT in generated SQL for Model.count

Hi all

Found a fringe case bug and made a patch: http://dev.rubyonrails.org/ticket/11502

<ticket_snippet> 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 paginated_finder plugin. </ticket_snippet>

Kind regards