Rails 3でmongoidを使用していますが、この問題に遭遇しました:
Shape モデルがあるとします。
class Shape
include Mongoid::Document
field :x, type: Integer
field :y, type: Integer
embedded_in :canvas
end
Canvas モデル (多くの Shapes を持っています):
class Canvas
include Mongoid::Document
field :name, type: String
embeds_many :shapes
end
次に、Canvas モデルには「多くの形状があります」。
Canvas から継承された Browser モデルがあります。
class Browser < Canvas
field :version, type: Integer
end
すると、Browswer モデルは「多くの形状を持つ」ようになります。
しかし、今では Shape から継承された "Circle" モデルがあります。
class Circle < Shape
field :radius, type: Float
end
そして、ブラウザモデルを「多くの形状を持つ」のではなく「多くの円を持つ」ようにしたいと考えています。つまり、Browser モデルの「has many」関係を「has many Shapes」から「has many Circles」に上書きしたいのです。
どうすればいいですか?