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:
parent
cef09015c7
commit
75b8ac80d9
3 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
7
activerecord/test/fixtures/posts.yml
vendored
7
activerecord/test/fixtures/posts.yml
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue