Permalink
Browse files

Don't reload belongs_to associations when assigning

  • Loading branch information...
cheald committed Feb 9, 2011
1 parent 7329d37 commit 41c518e289006d625bb886776ef4ef745db90c97
@@ -12,6 +12,11 @@ def replace(doc)
proxy_owner[association.foreign_key] = id
proxy_owner[association.type_key_name] = type
reset
unless doc.nil?
loaded
@target = doc
end
@target
end
protected
@@ -9,8 +9,13 @@ def replace(doc)
id = doc.id
end
reset
proxy_owner[association.foreign_key] = id
reload
unless doc.nil?
loaded
@target = doc
end
@target
end
protected
@@ -49,6 +49,12 @@ def post?
comment.post.should == post
comment.post.nil?.should be_false
end
should "not reload the association when replacing" do
post = @post_class.new(:name => 'mongomapper')
comment = @comment_class.new(:name => 'Foo!', :post => post)
comment.post.proxy_target.object_id.should == post.object_id
end
should "generate a new proxy when replacing the association" do
post1 = @post_class.create(:name => 'post1')

0 comments on commit 41c518e

Please sign in to comment.