Permalink
Browse files

Merge pull request #11791 from versioncontrol/includes_with_persisten…

…t_select

Includes with persistent select, fixes #11773
  • Loading branch information...
2 parents 2978af8 + 7cab255 commit 0df9149fd6b0ef4cd9003c1a9c406e2c586c9503 @rafaelfranca rafaelfranca committed Oct 13, 2013
@@ -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*
@@ -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
@@ -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 }

0 comments on commit 0df9149

Please sign in to comment.