Kenneth Kalmer
2008-Apr-01 21:44 UTC
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 -- Kenneth Kalmer kenneth.kalmer@gmail.com Folding@home stats http://fah-web.stanford.edu/cgi-bin/main.py?qtype=userpage&username=kenneth%2Ekalmer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---