提交 ba7634d3 编写于 作者: R Ryuta Kamizono

Merge pull request #36647 from...

Merge pull request #36647 from giraffate/fix_exists_with_distinct_and_offset_and_order_in_postgresql

Fix `relation.exists?` with giving `distinct`, `offset` and `order` for joined table
......@@ -354,7 +354,7 @@ def construct_relation_for_exists(conditions)
conditions = sanitize_forbidden_attributes(conditions)
if distinct_value && offset_value
relation = limit(1)
relation = except(:order).limit!(1)
else
relation = except(:select, :distinct, :order)._select!(ONE_AS_ONE).limit!(1)
end
......
......@@ -283,6 +283,11 @@ def test_exists_with_distinct_and_offset_and_select
assert_not Post.select(:body).distinct.offset(4).exists?
end
def test_exists_with_distinct_and_offset_and_eagerload_and_order
assert Post.eager_load(:comments).distinct.offset(10).merge(Comment.order(post_id: :asc)).exists?
assert_not Post.eager_load(:comments).distinct.offset(11).merge(Comment.order(post_id: :asc)).exists?
end
# Ensure +exists?+ runs without an error by excluding distinct value.
# See https://github.com/rails/rails/pull/26981.
def test_exists_with_order_and_distinct
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册