exclude ORDER BY clause when querying Relation#exists?
This commit is contained in:
parent
5b21bfa848
commit
74c6e80cab
@ -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?
|
||||
|
Loading…
Reference in New Issue
Block a user