提交 74c6e80c 编写于 作者: A Akira Matsuda

exclude ORDER BY clause when querying Relation#exists?

上级 5b21bfa8
......@@ -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?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册