diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-17 23:46:55 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-17 23:46:55 +0000 |
commit | 18057d2fb6017df988fadc6496f187c2e6208277 (patch) | |
tree | a98a31e6839a3383975aa0081e071a3e6343dd96 /activerecord/lib/active_record | |
parent | 4584376a914f8a8cee059943d80ba73d2d4e2627 (diff) | |
download | rails-18057d2fb6017df988fadc6496f187c2e6208277.tar.gz rails-18057d2fb6017df988fadc6496f187c2e6208277.tar.bz2 rails-18057d2fb6017df988fadc6496f187c2e6208277.zip |
Cache nil results for :included has_one associations also. Closes #5787.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4783 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 8f71734b3d..222bf6ca6a 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -870,7 +870,7 @@ module ActiveRecord end define_method("set_#{reflection.name}_target") do |target| - return if target.nil? + return if target.nil? and association_proxy_class == BelongsToAssociation association = association_proxy_class.new(self, reflection) association.target = target instance_variable_set("@#{reflection.name}", association) @@ -1311,11 +1311,15 @@ module ActiveRecord when :has_many, :has_and_belongs_to_many collection = record.send(join.reflection.name) collection.loaded - + return nil if record.id.to_s != join.parent.record_id(row).to_s or row[join.aliased_primary_key].nil? association = join.instantiate(row) collection.target.push(association) unless collection.target.include?(association) - when :has_one, :belongs_to + when :has_one + return if record.id.to_s != join.parent.record_id(row).to_s + association = join.instantiate(row) unless row[join.aliased_primary_key].nil? + record.send("set_#{join.reflection.name}_target", association) + when :belongs_to return if record.id.to_s != join.parent.record_id(row).to_s or row[join.aliased_primary_key].nil? association = join.instantiate(row) record.send("set_#{join.reflection.name}_target", association) |