diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-06 20:39:34 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-06 20:39:34 +0000 |
commit | 49c801b71d425543ae88e171b969b3316f022c2a (patch) | |
tree | a7a4fd2f16414b091fdb4c7c4335e300f15414f7 /activerecord/lib/active_record/associations | |
parent | 89ec75edc9a4d9064c0e644c5be0949f5119967c (diff) | |
download | rails-49c801b71d425543ae88e171b969b3316f022c2a.tar.gz rails-49c801b71d425543ae88e171b969b3316f022c2a.tar.bz2 rails-49c801b71d425543ae88e171b969b3316f022c2a.zip |
Added :include as an option for association declarations [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2898 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations')
4 files changed, 23 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 9dc0e26e10..528c42cea7 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -49,9 +49,13 @@ module ActiveRecord private def find_target if @options[:conditions] - @association_class.find_on_conditions(@owner[@association_class_primary_key_name], interpolate_sql(@options[:conditions])) + @association_class.find( + @owner[@association_class_primary_key_name], + :conditions => interpolate_sql(@options[:conditions]), + :include => @options[:include] + ) else - @association_class.find(@owner[@association_class_primary_key_name]) + @association_class.find(@owner[@association_class_primary_key_name], :include => @options[:include]) end end diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index a90d89a69b..2a51efb94f 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -90,7 +90,7 @@ module ActiveRecord if @options[:finder_sql] records = @association_class.find_by_sql(@finder_sql) else - records = find(:all) + records = find(:all, :include => @options[:include]) end @options[:uniq] ? uniq(records) : records diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 9ee06ffbcb..3027e26ce0 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -23,12 +23,12 @@ module ActiveRecord # DEPRECATED. def find_all(runtime_conditions = nil, orderings = nil, limit = nil, joins = nil) if @options[:finder_sql] - records = @association_class.find_by_sql(@finder_sql) + @association_class.find_by_sql(@finder_sql) else - sql = @finder_sql - sql += " AND (#{sanitize_sql(runtime_conditions)})" if runtime_conditions + conditions = @finder_sql + conditions += " AND (#{sanitize_sql(runtime_conditions)})" if runtime_conditions orderings ||= @options[:order] - records = @association_class.find_all(sql, orderings, limit, joins) + @association_class.find_all(conditions, orderings, limit, joins) end end @@ -105,7 +105,17 @@ module ActiveRecord end def find_target - find_all + if @options[:finder_sql] + @association_class.find_by_sql(@finder_sql) + else + @association_class.find(:all, + :conditions => @finder_sql, + :order => @options[:order], + :limit => @options[:limit], + :joins => @options[:joins], + :include => @options[:include] + ) + end end def count_records diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 18f84ee98f..edd9e53c19 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -57,7 +57,7 @@ module ActiveRecord private def find_target - @association_class.find(:first, :conditions => @finder_sql, :order => @options[:order]) + @association_class.find(:first, :conditions => @finder_sql, :order => @options[:order], :include => @options[:include]) end def target_obsolete? |