提交 c659cb85 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #26981 from kamipo/should_not_except_order_for_exists

Should except `:distinct` rather than `:order` for `exists?`
......@@ -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.
......
......@@ -321,7 +321,7 @@ def exists?(conditions = :none)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册