为什么has_many没有在这些Mongoid模型上工作?

时间:2011-10-01 15:55:52

标签: ruby mongodb mongoid

我有这些模特:

class Feed
  include Mongoid::Document
    field :name
    field :host
    field :user_name
        ...

    has_many :stores
end

class Store



include Mongoid::Document

    field :name
    field :store_id
    field :dealfeeds, type: Array
    ...

    belongs_to :feed
end

但是当我尝试通过Feed添加商店时,我收到了以下错误:

>> Feed.stores << Store.new
NoMethodError: undefined method `stores' for Feed:Class

>> Feed[:stores] << Store.new
NoMethodError: undefined method `[]' for Feed:Class

1 个答案:

答案 0 :(得分:1)

啊,傻,我。这些是对不在类上的实例的操作。