From 8d58bdda2069ee57b8d5088cd936bcf70224a66c Mon Sep 17 00:00:00 2001 From: sinsoku Date: Sat, 4 Jan 2020 19:26:53 +0900 Subject: [PATCH] Allow `or` in case of `from` clause with same value --- activerecord/lib/active_record/relation/from_clause.rb | 4 ++++ activerecord/test/cases/relation/or_test.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/activerecord/lib/active_record/relation/from_clause.rb b/activerecord/lib/active_record/relation/from_clause.rb index 93b129ce99..d1520f77aa 100644 --- a/activerecord/lib/active_record/relation/from_clause.rb +++ b/activerecord/lib/active_record/relation/from_clause.rb @@ -18,6 +18,10 @@ def empty? value.nil? end + def ==(other) + other.is_a?(FromClause) && name == other.name && value == other.value + end + def self.empty @empty ||= new(nil, nil).freeze end diff --git a/activerecord/test/cases/relation/or_test.rb b/activerecord/test/cases/relation/or_test.rb index e650da3a32..95375eb4ee 100644 --- a/activerecord/test/cases/relation/or_test.rb +++ b/activerecord/test/cases/relation/or_test.rb @@ -147,6 +147,7 @@ def test_structurally_incompatible_values Post.group(:author_id).group(:author_id).or(Post.group(:author_id)) Post.joins(:author).joins(:author).or(Post.joins(:author)) Post.left_outer_joins(:author).left_outer_joins(:author).or(Post.left_outer_joins(:author)) + Post.from("posts").or(Post.from("posts")) end end end -- GitLab