【发布时间】:2015-02-18 03:21:11
【问题描述】:
我有以下情况,我有一个文档需要嵌入到某些文档中,但为了可追溯性(例如,需要知道订阅每种类型的人数)我需要将其存储为不同的文档。因此,当我尝试保存一组默认类型时,它会说:
Mongoid::Errors::NoParent:
Problem:
Cannot persist embedded document Type without a parent document.
我不知道该怎么做或如何处理这种情况,感谢任何帮助或建议。
class Type
include Mongoid::Document
embedded_in :typeable, polymorphic: true
belongs_to :client
field :count, type: Integer # number of people interested in each Type
end
class Client
include Mongoid::Document
has_many :types
embeds_many :discounts, as: :discountable
end
class Discount
include Mongoid::Document
embeds_many :types, as: :typeable
embedded_in :discountable, polymorphic: true
end
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 mongoid mongoid3