提交 82b3ef7b 编写于 作者: B Boris Slobodin 提交者: Matthew Draper

exclude ORDER BY clause for exists? (#28699)

上级 fc0e3354
......@@ -383,7 +383,7 @@ def find_with_associations
end
def construct_relation_for_exists(relation, conditions)
relation = relation.except(:select, :distinct)._select!(ONE_AS_ONE).limit!(1)
relation = relation.except(:select, :distinct, :order)._select!(ONE_AS_ONE).limit!(1)
case conditions
when Array, Hash
......
......@@ -208,6 +208,11 @@ def test_exists_with_order_and_distinct
assert_equal true, Topic.order(:id).distinct.exists?
end
# Ensure +exists?+ runs without an error by excluding order value.
def test_exists_with_order
assert_equal true, Topic.order("invalid sql here").exists?
end
def test_exists_with_joins
assert_equal true, Topic.joins(:replies).where(replies_topics: { approved: true }).order("replies_topics.created_at DESC").exists?
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册