Skip to content

Commit

Permalink
Fixed obscure reload bug where single collection inherited classes th…
Browse files Browse the repository at this point in the history
…at didn't have associations defined in subclasses bombed when reloading.
  • Loading branch information
jnunemaker committed Dec 14, 2009
1 parent 0f3dad7 commit e12ceb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo_mapper/document.rb
Expand Up @@ -427,7 +427,7 @@ def destroy

def reload
doc = self.class.find(_id)
self.class.associations.each { |name, assoc| send(name).reset }
self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) }
self.attributes = doc.attributes
self
end
Expand Down
9 changes: 9 additions & 0 deletions test/functional/test_document.rb
Expand Up @@ -962,6 +962,8 @@ class ::DocParent
class ::DocDaughter < ::DocParent; end
class ::DocSon < ::DocParent; end
class ::DocGrandSon < ::DocSon; end

DocSon.many :children, :class_name => 'DocGrandSon'

@parent = DocParent.new({:name => "Daddy Warbucks"})
@daughter = DocDaughter.new({:name => "Little Orphan Annie"})
Expand Down Expand Up @@ -1100,6 +1102,13 @@ class ::DocGrandSon < ::DocSon; end
DocParent.delete_all
}.should change { DocParent.count }.by(-2)
end

should "be able to reload parent inherited class" do
brian = DocParent.create(:name => 'Brian')
brian.name = 'B-Dawg'
brian.reload
brian.name.should == 'Brian'
end
end

context "timestamping" do
Expand Down

0 comments on commit e12ceb5

Please sign in to comment.