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

Merged
merged 1 commit into from May 10, 2013
Commits on May 10, 2013
  1. 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#distinct_value.
    
    Rather than build a select distinct clause in #construct_limited_ids_condition,
    I set #distinct! and pass just the columns into the select statement.
    This requires introducing a #columns_for_distinct method to return the
    select columns but not the statement itself.