Skip to content
This repository
Browse code

Fix behaviour of foo.has_many_through_association.select('custom sele…

…ct') [#6089 state:resolved]
  • Loading branch information...
commit 030480ac1f4fbf8bf74a0d9298544426caf26894 1 parent 85683f2
Michał Łomnicki authored December 12, 2010 tenderlove committed December 23, 2010
4  activerecord/lib/active_record/associations/through_association_scope.rb
@@ -63,8 +63,8 @@ def construct_from
63 63
       end
64 64
 
65 65
       def construct_select(custom_select = nil)
66  
-        distinct = "DISTINCT " if @reflection.options[:uniq]
67  
-        custom_select || @reflection.options[:select] || "#{distinct}#{@reflection.quoted_table_name}.*"
  66
+        distinct = "DISTINCT #{@reflection.quoted_table_name}.*" if @reflection.options[:uniq]
  67
+        custom_select || @reflection.options[:select] || distinct
68 68
       end
69 69
 
70 70
       def construct_joins
5  activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -514,4 +514,9 @@ def test_joining_has_many_through_belongs_to
514 514
 
515 515
     assert_equal [posts(:eager_other)], posts
516 516
   end
  517
+
  518
+  def test_select_chosen_fields_only
  519
+    author = authors(:david)
  520
+    assert_equal ['body'], author.comments.select('comments.body').first.attributes.keys
  521
+  end
517 522
 end

0 notes on commit 030480a

Please sign in to comment.
Something went wrong with that request. Please try again.