Mongoid和数据库结构的变化

时间:2012-08-28 17:00:09

标签: ruby mongodb mongoid

我想要做的具体改变是我想要摆脱基类模型。假设我有一个基类Fruit,然后我有两个不同的延伸水果类Orange和Banana。

所以我有这样的事情:

class Fruit
  include Mongoid::Document
  field :weight, type: Integer
end
class Orange < Fruit
end
class Banana < Fruit
end

我想将其转换为此而不会丢失任何数据或对水果的引用:

class Orange
  include Mongoid::Document
  field :weight, type: Integer
end
class Banana
  include Mongoid::Document
  field :weight, type: Integer
end

P.S。请不要质疑我为什么想要打破DRY规则并摆脱遗产的原因。我有我的理由,他们很好:)最终的想法是将重复的东西重构为一个模块。

0 个答案:

没有答案