1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

exclude ORDER BY clause for exists? (#28699)

This commit is contained in:
Boris Slobodin 2017-04-09 16:05:13 -07:00 committed by Matthew Draper
parent ee0f5c3f59
commit 24ac36be71
2 changed files with 6 additions and 1 deletions

View file

@ -383,7 +383,7 @@ module ActiveRecord
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

View file

@ -208,6 +208,11 @@ class FinderTest < ActiveRecord::TestCase
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