Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #11773 when using includes combined with select, the select sta…

…tement was overwritten.
  • Loading branch information...
commit 7cab255a97fceb48e3b59b3d39b5fe58c6dad54b 1 parent d2d6e4a
Edo Balvers ehtb authored
6 activerecord/CHANGELOG.md
View
@@ -199,6 +199,12 @@
*Yves Senn*
+* Fixes bug when using includes combined with select, the select statement was overwritten.
+
+ Fixes #11773
+
+ *Edo Balvers*
+
* Load fixtures from linked folders.
*Kassio Borges*
2  activerecord/lib/active_record/relation/finder_methods.rb
View
@@ -261,7 +261,7 @@ def construct_relation_for_association_calculations
end
def construct_relation_for_association_find(join_dependency)
- relation = except(:select).select(join_dependency.columns)
+ relation = except(:select).select(join_dependency.columns + select_values)
apply_join_dependency(relation, join_dependency)
end
8 activerecord/test/cases/relations_test.rb
View
@@ -486,6 +486,14 @@ def test_default_scoping_finder_methods
assert_equal Developer.where(name: 'David').map(&:id).sort, developers
end
+ def test_includes_with_select
+ query = Post.select('comments_count AS ranking').order('ranking').includes(:comments)
+ .where(comments: { id: 1 })
+
+ assert_equal ['comments_count AS ranking'], query.select_values
+ assert_equal 1, query.to_a.size
+ end
+
def test_loading_with_one_association
posts = Post.preload(:comments)
post = posts.find { |p| p.id == 1 }
Please sign in to comment.
Something went wrong with that request. Please try again.