Skip to content

Commit

Permalink
Merge pull request mongomapper#414 from md5/declare-belongs_to-type-key
Browse files Browse the repository at this point in the history
Declare type key on polymorphic belongs_to
  • Loading branch information
brianhempel committed May 23, 2012
2 parents e582032 + c8105c6 commit 28d005e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Expand Up @@ -17,6 +17,7 @@ def proxy_class

def setup(model)
model.key foreign_key, ObjectId unless model.key?(foreign_key)
model.key type_key_name, String unless model.key?(type_key_name) if polymorphic?
super
add_touch_callbacks if touch?
end
Expand Down
4 changes: 3 additions & 1 deletion test/functional/associations/test_many_documents_as_proxy.rb
Expand Up @@ -13,7 +13,9 @@ def setup

should "add type and id key to polymorphic class base" do
PostComment.keys.keys.should include('commentable_type')
PostComment.keys['commentable_type'].type.should == String
PostComment.keys.keys.should include('commentable_id')
PostComment.keys['commentable_id'].type.should == ObjectId
end

should "allow adding to association like it was an array" do
Expand Down Expand Up @@ -226,4 +228,4 @@ def setup
end
end
end
end
end

0 comments on commit 28d005e

Please sign in to comment.