diff options
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 8c91aeeed4..3a3966bb8a 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -39,7 +39,7 @@ module ActiveRecord def find_target @reflection.klass.find(:all, - :select => "#{@reflection.table_name}.*", + :select => construct_select, :conditions => construct_conditions, :from => construct_from, :order => @reflection.options[:order], @@ -73,6 +73,14 @@ module ActiveRecord "#{@reflection.table_name}, #{@owner.class.reflections[@reflection.options[:through]].table_name}" end + def construct_select + selected = ["#{@reflection.table_name}.*"] + if @reflection.options[:piggyback] + selected += [@reflection.options[:piggyback]].flatten.collect { |field| "#{@owner.class.reflections[@reflection.options[:through]].table_name}.#{field}" } + end + selected.join(', ') + end + def construct_scope { :find => { :conditions => construct_conditions }, |