diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-11-17 18:27:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-17 18:27:25 -0500 |
commit | c659cb8561f03c2e0b29da0379a9c341400e03bd (patch) | |
tree | fc8ed92f3b556f00cbf98759c574922bba347dab /activerecord | |
parent | 6e63b0aa137c8e231e77989a3c66ff9df6595602 (diff) | |
parent | 2bf7c30049558c2503f20e9810fdf4727650fe99 (diff) | |
download | rails-c659cb8561f03c2e0b29da0379a9c341400e03bd.tar.gz rails-c659cb8561f03c2e0b29da0379a9c341400e03bd.tar.bz2 rails-c659cb8561f03c2e0b29da0379a9c341400e03bd.zip |
Merge pull request #26981 from kamipo/should_not_except_order_for_exists
Should except `:distinct` rather than `:order` for `exists?`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 7f4be54dbb..a8bed82e19 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -14,7 +14,8 @@ *Pavel Evstigneev* -* Avoid `unscope(:order)` when `limit_value` is presented for `count`. +* Avoid `unscope(:order)` when `limit_value` is presented for `count` + and `exists?`. If `limit_value` is presented, records fetching order is very important for performance. We should not unscope the order in the case. diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 97a819c5af..55ded4c6d0 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -321,7 +321,7 @@ module ActiveRecord relation = apply_join_dependency(self, construct_join_dependency(eager_loading: false)) return false if ActiveRecord::NullRelation === relation - relation = relation.except(:select, :order).select(ONE_AS_ONE).limit(1) + relation = relation.except(:select, :distinct).select(ONE_AS_ONE).limit(1) case conditions when Array, Hash |