Skip to content

Commit

Permalink
type_key_name should be "_type" for ManyAssociation and OneAssociatio…
Browse files Browse the repository at this point in the history
…n, only "#{as}_type" for BelongsToAssociation
  • Loading branch information
brianhempel committed Nov 25, 2011
1 parent afcdb5b commit bac33b7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/mongo_mapper/plugins/associations/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def embeddable?
end

def type_key_name
"#{as}_type"
"_type"
end

def as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module MongoMapper
module Plugins
module Associations
class BelongsToAssociation < SingleAssociation
def type_key_name
"#{as}_type"
end

def embeddable?
false
end
Expand Down
4 changes: 0 additions & 4 deletions lib/mongo_mapper/plugins/associations/many_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def class_name
@class_name ||= options[:class_name] || name.to_s.singularize.camelize
end

def type_key_name
"_type"
end

# hate this, need to revisit
def proxy_class
@proxy_class ||= if klass.embeddable?
Expand Down
6 changes: 6 additions & 0 deletions test/unit/associations/test_one_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
class OneAssociationTest < Test::Unit::TestCase
include MongoMapper::Plugins::Associations

context "type_key_name" do
should "be _type" do
OneAssociation.new(:foo).type_key_name.should == '_type'
end
end

context "embeddable?" do
should "be true if class is embeddable" do
base = OneAssociation.new(:media)
Expand Down

0 comments on commit bac33b7

Please sign in to comment.