aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2005-12-20 20:32:47 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2005-12-20 20:32:47 +0000
commit1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace (patch)
tree2928e565d896bfd8e0e0f8cb3829a8c4a012359a /activerecord/lib/active_record
parent1235d26bfbc99a7b7466bddb8ff69eecc585d27f (diff)
downloadrails-1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace.tar.gz
rails-1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace.tar.bz2
rails-1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace.zip
added :piggyback option to has_many :through relationships to pick up values from the join table as needed
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3323 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb10
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 583f5f8044..8ee6eca15f 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -881,7 +881,7 @@ module ActiveRecord
:class_name, :table_name, :foreign_key,
:exclusively_dependent, :dependent,
:select, :conditions, :include, :order, :group, :limit, :offset,
- :as, :through,
+ :as, :through, :piggyback,
:finder_sql, :counter_sql,
:before_add, :after_add, :before_remove, :after_remove,
:extend
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 },