aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-09-28 18:34:24 +0900
committerGitHub <noreply@github.com>2018-09-28 18:34:24 +0900
commitf06d89c6043854fdf2cfd81265a5f852e77fa07b (patch)
treed92fac75bea553e622d6d653461d97273e5d4149 /activerecord/lib
parent2ab0df00b69335986f1116b7bea17c1ed0f52d9f (diff)
parentd76e3e12800414551ec42e17832227b820402007 (diff)
downloadrails-f06d89c6043854fdf2cfd81265a5f852e77fa07b.tar.gz
rails-f06d89c6043854fdf2cfd81265a5f852e77fa07b.tar.bz2
rails-f06d89c6043854fdf2cfd81265a5f852e77fa07b.zip
Merge pull request #34013 from bogdan/relation-merge-from
Bugfix ActiveRecord::Relation#merge special case of from clause
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/merger.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 07b16a0740..4de7465128 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -171,9 +171,7 @@ module ActiveRecord
end
def merge_clauses
- if relation.from_clause.empty? && !other.from_clause.empty?
- relation.from_clause = other.from_clause
- end
+ relation.from_clause = other.from_clause if replace_from_clause?
where_clause = relation.where_clause.merge(other.where_clause)
relation.where_clause = where_clause unless where_clause.empty?
@@ -181,6 +179,11 @@ module ActiveRecord
having_clause = relation.having_clause.merge(other.having_clause)
relation.having_clause = having_clause unless having_clause.empty?
end
+
+ def replace_from_clause?
+ relation.from_clause.empty? && !other.from_clause.empty? &&
+ relation.klass.base_class == other.klass.base_class
+ end
end
end
end