Skip to content

Loading…

Fix FinderMethods#exists? sql generation to make picky sql servers happy - 3 0 stable #1141

Closed
wants to merge 1 commit into from

4 participants

@iaddict

Minimal change to query generation of FinderMethods#exists? that makes SQLServer and others happy that do not like columns without an alias.

Without this patch MS-SQLServer doesn't like the generated SQL and barks for FinderMethods#exists?, ie:

ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: No column was specified for column 2 of 't'.: SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY huhu.id) AS _row_num, 1 FROM huhu WHERE huhu.[id] = 83287) AS t WHERE t._row_num BETWEEN 1 AND 1

@iaddict iaddict Minimal change to query generation of FinderMethods#exists? that make…
…s SQLServer and others happy that do not like columns without an alias.
22762d8
@idev

+1 please fix

@jonkessler

@iaddict Is this still an issue? If not, please close it. Thanks.

@rafaelfranca
Ruby on Rails member

This pull request is for a no longer supported Rails version. If you still have this issue please open a new pull request pointing to master.

Thank you so much for your time.

@rafaelfranca rafaelfranca added a commit that referenced this pull request
@rafaelfranca rafaelfranca Add test to column alias in `exists?` SQL.
This behavior was added in dd286a4

Closes #1139.

Fixes #2553, #1141, #1623 and #2062.
179276e
@rafaelfranca rafaelfranca added a commit that referenced this pull request
@rafaelfranca rafaelfranca Add test to column alias in `exists?` SQL.
This behavior was added in be4ecdc.

Closes #1139.

Fixes #2553, #1141, #1623 and #2062.
6cc5e9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 19, 2011
  1. @iaddict

    Minimal change to query generation of FinderMethods#exists? that make…

    iaddict committed
    …s SQLServer and others happy that do not like columns without an alias.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/relation/finder_methods.rb
View
2 activerecord/lib/active_record/relation/finder_methods.rb
@@ -173,7 +173,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
Something went wrong with that request. Please try again.