exclude ORDER BY clause when querying Relation#exists?

This commit is contained in:
Akira Matsuda 2011-11-09 04:46:11 +09:00
parent 5b21bfa848
commit 74c6e80cab
2 changed files with 6 additions and 1 deletions

@ -191,7 +191,7 @@ def exists?(id = false)
join_dependency = construct_join_dependency_for_association_find
relation = construct_relation_for_association_find(join_dependency)
relation = relation.except(:select).select("1").limit(1)
relation = relation.except(:select, :order).select("1").limit(1)
case id
when Array, Hash

@ -57,6 +57,11 @@ def test_exists_with_nil_arg
assert Topic.first.replies.exists?
end
# ensures +exists?+ runs valid SQL by excluding order value
def test_exists_with_order
assert Topic.order(:id).uniq.exists?
end
def test_does_not_exist_with_empty_table_and_no_args_given
Topic.delete_all
assert !Topic.exists?