Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Mongoid与数据库结构的变化_Ruby_Mongodb_Mongoid - Fatal编程技术网

Ruby Mongoid与数据库结构的变化

Ruby Mongoid与数据库结构的变化,ruby,mongodb,mongoid,Ruby,Mongodb,Mongoid,我想做的具体更改是,我想去掉模型的基类。假设我有一个基类水果,然后我有两个不同的扩展水果类橙色和香蕉 所以我有这样的想法: class Fruit include Mongoid::Document field :weight, type: Integer end class Orange < Fruit end class Banana < Fruit end 顺便说一句,请不要质疑我为什么要打破干涸的规则,摆脱遗产。我有我的理由,它们是好的:)最终的想法是将重复的东西重

我想做的具体更改是,我想去掉模型的基类。假设我有一个基类水果,然后我有两个不同的扩展水果类橙色和香蕉

所以我有这样的想法:

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

顺便说一句,请不要质疑我为什么要打破干涸的规则,摆脱遗产。我有我的理由,它们是好的:)最终的想法是将重复的东西重构成一个模块。

我猜你必须手工将
水果
集合分成两部分(
橙子
香蕉
),然后才能工作。SCI的
fruits
中应该有一个
type
字段,再加上一点JavaScript,您就可以在MongoDB中修复数据了。您能再详细说明一下吗?要在数据库和Rails端完成这项工作,需要采取哪些步骤?使用以下内容是否有益:或者我应该如何使用所需的JavaScript命令运行迁移?
class Orange
  include Mongoid::Document
  field :weight, type: Integer
end
class Banana
  include Mongoid::Document
  field :weight, type: Integer
end