我在MongoDB和MongoMapper中使用Rails。我的问题是,我有一个继承自另一个类的类,并且我想省略其中一个键。例如:
class A
include MongoMapper::EmbeddedDocument
many :items
#Other keys I want
end
class Item < A
include MongoMapper::EmbeddedDocument
#Included Keys from A
#Other Keys that I want
end这里的问题是Item继承了A of here :items的关系。我怎样才能防止这种情况呢?
发布于 2011-11-12 01:26:21
这一点:
是一个继承自另一个类的类,我想省略其中的一个键
指示您没有有效的继承关系。也许你想要更多这样的东西:
class B
# Common things for A and C
end
class A < B
many :items
# Other things that shouldn't be in B or C
end
class C < B
# Other keys you want that aren't already in B
end试图缩小派生类的接口是一个信号,表明你做错了什么,需要重新考虑你的层次结构。
https://stackoverflow.com/questions/8097570
复制相似问题