This project is archived and is in readonly mode.
select() ignored in subquery when querying with count()
Reported by James | September 24th, 2010 @ 04:31 PM
Login.where(:date => Date.today).select("DISTINCT player_id").all
As expected, this produces the following query:
SELECT DISTINCT player_id FROM `logins` WHERE (`logins`.`date` = '2010-09-24')
The following uses .count instead of .all and ignores the select("DISTINCT..."):
Login.where(:date => Date.today).select("DISTINCT player_id").count
SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM `logins` WHERE (`logins`.`date` = '2010-09-24')) AS subquery
Comments and changes to this ticket
-
gnufied September 26th, 2010 @ 06:01 AM
- Assigned user set to Aaron Patterson
- Tag set to arel activerecord bug rails3, verified
Verified. The problem does exist (and returned value of count can be potentially wrong).
I am trying to get a patch, but in the meanwhile assigning to tenderlove.
-
gnufied September 26th, 2010 @ 06:26 AM
Hmm, the problem seems to have been fixed on master (Both Arel and Rails). In which case, the fix should be backported to Rails-3.0 stable?
-
Aaron Patterson September 27th, 2010 @ 06:20 PM
- State changed from new to resolved
- Importance changed from to Low
This should be fixed with ARel 2.0, so the 3-0-stable branch should work now.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>