Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11791 from versioncontrol/includes_with_persisten…

…t_select

Includes with persistent select, fixes #11773
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/finder_methods.rb
  • Loading branch information...
commit 645e87fa1c01fcc687ce90222a9766111b08a574 1 parent 2d44771
@rafaelfranca rafaelfranca authored
View
6 activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## unreleased ##
+* Fixes bug when using includes combined with select, the select statement was overwritten.
+
+ Fixes #11773.
+
+ *Edo Balvers*
+
* Objects instantiated using a null relationship will now retain the
attributes of the where clause.
View
2  activerecord/lib/active_record/relation/finder_methods.rb
@@ -222,7 +222,7 @@ def construct_relation_for_association_calculations
end
def construct_relation_for_association_find(join_dependency)
- relation = except(:includes, :eager_load, :preload, :select).select(join_dependency.columns)
+ relation = except(:includes, :eager_load, :preload, :select).select(join_dependency.columns + select_values)
apply_join_dependency(relation, join_dependency)
end
View
8 activerecord/test/cases/relations_test.rb
@@ -476,6 +476,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.