首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在MongoMapper中防止继承

在MongoMapper中防止继承
EN

Stack Overflow用户
提问于 2011-11-12 01:15:38
回答 1查看 52关注 0票数 0

我在MongoDB和MongoMapper中使用Rails。我的问题是,我有一个继承自另一个类的类,并且我想省略其中一个键。例如:

代码语言:javascript
复制
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的关系。我怎样才能防止这种情况呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-12 01:26:21

这一点:

是一个继承自另一个类的类,我想省略其中的一个键

指示您没有有效的继承关系。也许你想要更多这样的东西:

代码语言:javascript
复制
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

试图缩小派生类的接口是一个信号,表明你做错了什么,需要重新考虑你的层次结构。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8097570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档