1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Dont initialize the association proxy for nil records

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1165 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-04-14 07:49:13 +00:00
parent cef09015c7
commit 75b8ac80d9
3 changed files with 12 additions and 0 deletions

View file

@ -557,6 +557,7 @@ module ActiveRecord
end
define_method("set_#{association_name}_target") do |target|
return if target.nil?
association = association_proxy_class.new(self,
association_name, association_class_name,
association_class_primary_key_name, options)

View file

@ -29,6 +29,10 @@ class EagerAssociationTest < Test::Unit::TestCase
assert_equal 2, posts.first.comments.size
end
def test_loading_with_no_associations
assert_nil Post.find(@authorless.id, :include => :author).author
end
def test_eager_association_loading_with_belongs_to
comments = Comment.find(:all, :include => :post)
assert_equal @welcome.title, comments.first.post.title

View file

@ -11,3 +11,10 @@ thinking:
title: So I was thinking
body: Like I hopefully always am
type: SpecialPost
authorless:
id: 3
author_id: ""
title: I don't have any comments
body: I just don't want to
type: Post