diff options
author | Chalo Fernandez <chalofa@gmail.com> | 2018-06-06 02:41:13 -0500 |
---|---|---|
committer | Chalo Fernandez <chalofa@gmail.com> | 2018-06-06 02:43:46 -0500 |
commit | fd689d9fb119ddababae55da40004815f7c4b32d (patch) | |
tree | 2cc95af76b3d5b6a6e75d668b82772dd7e3bcdc3 /activerecord/lib/active_record/associations | |
parent | d0d3e964920602aa710507f6717010d852e37c86 (diff) | |
download | rails-fd689d9fb119ddababae55da40004815f7c4b32d.tar.gz rails-fd689d9fb119ddababae55da40004815f7c4b32d.tar.bz2 rails-fd689d9fb119ddababae55da40004815f7c4b32d.zip |
Child joins should be aliased when merging relations
Rails 5.2 does not alias child joins, causing an error about duplicated table/fields:
Example:
Using some code like:
`Post.joins(:author, :categorizations).merge(Author.select(:id)).merge(Categorization.joins(:author))`
*Before this fix:*
`
SELECT ... FROM "posts" INNER JOIN "authors" ON ... INNER JOIN "authors" ON ...
`
*After this fix:*
`
SELECT ... FROM "posts" INNER JOIN "authors" ON ... INNER JOIN "authors" "authors_categorizations" ON ...
`
Before 5.2, Rails aliased the joins, but wrongfully transformed them into a LEFT OUTER JOIN.
This fix will keep them as INNER JOINS, but make sure child joins are aliased, to avoid errors.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index f88e383fe0..c1faa021aa 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -88,7 +88,7 @@ module ActiveRecord walk join_root, oj.join_root else oj.join_root.children.flat_map { |child| - make_join_constraints(oj.join_root, child, join_type) + make_join_constraints(oj.join_root, child, join_type, true) } end } |