1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixes #11773 when using includes combined with select, the select statement was overwritten.

This commit is contained in:
Edo Balvers 2013-08-09 12:58:46 +02:00
parent d2d6e4a980
commit 7cab255a97
3 changed files with 15 additions and 1 deletions

View file

@ -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*

View file

@ -261,7 +261,7 @@ module ActiveRecord
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

View file

@ -486,6 +486,14 @@ class RelationTest < ActiveRecord::TestCase
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 }