1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #26981 from kamipo/should_not_except_order_for_exists

Should except `:distinct` rather than `:order` for `exists?`
This commit is contained in:
Rafael França 2016-11-17 18:27:25 -05:00 committed by GitHub
commit c659cb8561
2 changed files with 3 additions and 2 deletions

View file

@ -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.

View file

@ -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