Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix FinderMethods#exists? sql generation to make picky sql servers happy #1139

Closed
wants to merge 6 commits into
from
@@ -185,7 +185,7 @@ def exists?(id = nil)
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).select("1 AS _one").limit(1)
case id
when Array, Hash
@@ -71,6 +71,13 @@ def test_exists_query_logging
assert_match(/SELECT .*?FROM .?developers.?/i, @logger.logged(:debug).last)
end
+ def test_exists_query_alias
+ Developer.exists? 1
+ wait
+ assert_equal 1, @logger.logged(:debug).size
+ assert_match(/SELECT .*?1 AS _one.*? FROM .?developers.?/i, @logger.logged(:debug).last)
+ end
+
def test_cached_queries
ActiveRecord::Base.cache do
Developer.all