mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Properly include the from
clause when merging relations
The code that set the from clause was removed in
bdc5141652
. I did not give any reason for
doing so. My assumption was that I intended to change it to use the
clause objects, but forgot. We appeared to not have test coverage for
this case.
Fixes #22996
This commit is contained in:
parent
b7cce1c0a9
commit
f138bea5da
2 changed files with 10 additions and 0 deletions
|
@ -141,6 +141,9 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def merge_single_values
|
||||
if relation.from_clause.empty?
|
||||
relation.from_clause = other.from_clause
|
||||
end
|
||||
relation.lock_value ||= other.lock_value
|
||||
|
||||
unless other.create_with_value.blank?
|
||||
|
|
|
@ -104,6 +104,13 @@ class RelationMergingTest < ActiveRecord::TestCase
|
|||
post = PostThatLoadsCommentsInAnAfterSaveHook.create!(title: "First Post", body: "Blah blah blah.")
|
||||
assert_equal "First comment!", post.comments.where(body: "First comment!").first_or_create.body
|
||||
end
|
||||
|
||||
def test_merging_with_from_clause
|
||||
relation = Post.all
|
||||
assert relation.from_clause.empty?
|
||||
relation = relation.merge(Post.from("posts"))
|
||||
refute relation.from_clause.empty?
|
||||
end
|
||||
end
|
||||
|
||||
class MergingDifferentRelationsTest < ActiveRecord::TestCase
|
||||
|
|
Loading…
Reference in a new issue