From 030480ac1f4fbf8bf74a0d9298544426caf26894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81omnicki?= Date: Sun, 12 Dec 2010 01:37:56 +0100 Subject: Fix behaviour of foo.has_many_through_association.select('custom select') [#6089 state:resolved] --- .../lib/active_record/associations/through_association_scope.rb | 4 ++-- .../test/cases/associations/has_many_through_associations_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'activerecord') 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 -- cgit v1.2.3