aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTakayuki Nakata <f.seasons017@gmail.com>2019-07-10 22:53:52 +0900
committerTakayuki Nakata <f.seasons017@gmail.com>2019-07-10 22:53:52 +0900
commitd9587feb5fab65c4c5bb7a5372f7319f50565f60 (patch)
treea8778bb991fd2f524d1660f1b7b8e39a065437d9 /activerecord/lib
parent6e40b131d2c7208e116d267e4b40dcf621f8b442 (diff)
downloadrails-d9587feb5fab65c4c5bb7a5372f7319f50565f60.tar.gz
rails-d9587feb5fab65c4c5bb7a5372f7319f50565f60.tar.bz2
rails-d9587feb5fab65c4c5bb7a5372f7319f50565f60.zip
Fix `relation.exists?` with giving `distinct`, `offset` and `order` for joined table
The error happens in PostgreSQL when using `relation.exists?` with `distinct`, `offset` and `order` for joined table. However, the error does not happen if either `distinct` or `offset` is removed. This behavior is confusing. Fixes #36632
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 6deb9c7da8..b4a5aa0d34 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -354,7 +354,7 @@ module ActiveRecord
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