Permalink
Browse files

exclude ORDER BY clause when querying Relation#exists?

  • Loading branch information...
amatsuda committed Nov 8, 2011
1 parent 5b21bfa commit 74c6e80cabd8e3b7751fc3a32c9ad95c1780054b
@@ -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?

0 comments on commit 74c6e80

Please sign in to comment.