aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMichał Łomnicki <michal.lomnicki@gmail.com>2010-12-12 01:37:56 +0100
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-23 15:19:17 -0800
commit030480ac1f4fbf8bf74a0d9298544426caf26894 (patch)
treeffbd1e3614e50ce045b0d095f3ed49b3751f3adf /activerecord
parent85683f2a79dbf81130361cb6426786cf6b0d1925 (diff)
downloadrails-030480ac1f4fbf8bf74a0d9298544426caf26894.tar.gz
rails-030480ac1f4fbf8bf74a0d9298544426caf26894.tar.bz2
rails-030480ac1f4fbf8bf74a0d9298544426caf26894.zip
Fix behaviour of foo.has_many_through_association.select('custom select') [#6089 state:resolved]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/through_association_scope.rb4
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb
index 99920d4c63..c11fce5db0 100644
--- a/activerecord/lib/active_record/associations/through_association_scope.rb
+++ b/activerecord/lib/active_record/associations/through_association_scope.rb
@@ -63,8 +63,8 @@ module ActiveRecord
end
def construct_select(custom_select = nil)
- distinct = "DISTINCT " if @reflection.options[:uniq]
- custom_select || @reflection.options[:select] || "#{distinct}#{@reflection.quoted_table_name}.*"
+ distinct = "DISTINCT #{@reflection.quoted_table_name}.*" if @reflection.options[:uniq]
+ custom_select || @reflection.options[:select] || distinct
end
def construct_joins
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index d237273464..6b71e73718 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -514,4 +514,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [posts(:eager_other)], posts
end
+
+ def test_select_chosen_fields_only
+ author = authors(:david)
+ assert_equal ['body'], author.comments.select('comments.body').first.attributes.keys
+ end
end