From 5c1be2812ddc81a3ac5b65c8a461a9622e41b31c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 22 Mar 2008 02:20:37 +0000 Subject: has_one :through supports :source_type. Fix up some tests. References #4756. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9075 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/association_preload.rb | 9 +++++++-- activerecord/lib/active_record/associations.rb | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 0c31c85bb0..ad9b9d6488 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -165,8 +165,13 @@ module ActiveRecord through_records = [] records.compact.each do |record| proxy = record.send(through_association) - through_records << proxy.target - proxy.reset + + if proxy.respond_to?(:target) + through_records << proxy.target + proxy.reset + else # this is a has_one :through reflection + through_records << proxy if proxy + end end through_records = through_records.flatten else diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index aa68a42c44..068f2f9de2 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1326,7 +1326,7 @@ module ActiveRecord def create_has_one_through_reflection(association_id, options) options.assert_valid_keys( - :class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source + :class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source, :source_type ) create_reflection(:has_one, association_id, options, self) end -- cgit v1.2.3