aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-11-11 03:54:10 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-11-11 04:02:09 +0900
commit4528dd6327f35d3139a48cbac9c9192f2253cbad (patch)
treec904f447f7c72141b62bfff4ad2c58fe2b3a5f51 /activerecord/test/cases/relation_test.rb
parentfc7a6c738122ba9dd6eff4ede08d67e86a3f0ea7 (diff)
downloadrails-4528dd6327f35d3139a48cbac9c9192f2253cbad.tar.gz
rails-4528dd6327f35d3139a48cbac9c9192f2253cbad.tar.bz2
rails-4528dd6327f35d3139a48cbac9c9192f2253cbad.zip
Relation merging should keep joining order
`joins_values.partition` will break joins values order. It should be kept as user intended order. Fixes #15488.
Diffstat (limited to 'activerecord/test/cases/relation_test.rb')
-rw-r--r--activerecord/test/cases/relation_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
index fd5985ffe7..8362722e12 100644
--- a/activerecord/test/cases/relation_test.rb
+++ b/activerecord/test/cases/relation_test.rb
@@ -274,6 +274,15 @@ module ActiveRecord
assert_equal({ 2 => 1, 4 => 3, 5 => 1 }, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count)
end
+ def test_relation_merging_keeps_joining_order
+ authors = Author.where(id: 1)
+ posts = Post.joins(:author).merge(authors)
+ comments = Comment.joins(:post).merge(posts)
+ ratings = Rating.joins(:comment).merge(comments)
+
+ assert_equal 3, ratings.count
+ end
+
class EnsureRoundTripTypeCasting < ActiveRecord::Type::Value
def type
:string