From d9587feb5fab65c4c5bb7a5372f7319f50565f60 Mon Sep 17 00:00:00 2001 From: Takayuki Nakata Date: Wed, 10 Jul 2019 22:53:52 +0900 Subject: 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 --- activerecord/lib/active_record/relation/finder_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3