Permalink
Browse files

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

…tement was overwritten.
  • Loading branch information...
1 parent d2d6e4a commit 7cab255a97fceb48e3b59b3d39b5fe58c6dad54b @ehtb ehtb committed Aug 9, 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 7cab255

Please sign in to comment.