Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

select() ignored in subquery when querying with count()

#5698
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

Reported by James · September 24th, 2010 @ 04:31 PM

State: resolved
Milestone: none
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. gnufied
    gnufied
    • 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.

    September 26th, 2010 @ 06:01 AM

  2. gnufied
    gnufied

    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?

    September 26th, 2010 @ 06:26 AM

  3. Aaron Patterson
    Aaron Patterson
    • 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.

    September 27th, 2010 @ 06:20 PM