diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-08 12:39:50 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-08 12:39:50 -0800 |
commit | 6e87281b5f9f6f7abf0ef93448c63396419f1920 (patch) | |
tree | 515d82113e061b166d26cfc442f78634cbc512cb /activerecord | |
parent | 5b21bfa84862807d62b297de76805de8afcee511 (diff) | |
parent | 74c6e80cabd8e3b7751fc3a32c9ad95c1780054b (diff) | |
download | rails-6e87281b5f9f6f7abf0ef93448c63396419f1920.tar.gz rails-6e87281b5f9f6f7abf0ef93448c63396419f1920.tar.bz2 rails-6e87281b5f9f6f7abf0ef93448c63396419f1920.zip |
Merge pull request #3572 from amatsuda/ar_exists_uniq_order
exclude ORDER BY clause when querying Relation#exists?
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 7eeb3dde70..3c8e0f2052 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -191,7 +191,7 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 3088ab012f..69754d23b9 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -57,6 +57,11 @@ class FinderTest < ActiveRecord::TestCase 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? |