Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT" #6523

Closed
wants to merge 1 commit into
from
Commits on Jun 11, 2012
  1. @Empact

    Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"

    Empact committed May 28, 2012
    The combination of a :uniq => true association and the #distinct call
    in #construct_limited_ids_condition combine to create invalid SQL, because
    we're explicitly selecting DISTINCT, and also sending #distinct on to AREL,
    via the relation#uniq_value.
    
    I unset relation#uniq_value in the limited ids lookup so that Arel doesn't
    apply the DISTINCT that we're already applying. This only affects the limited
    ids lookup query, and only in the problematic case where uniq_value was true.