Jeremy Smith
Jeremy Smith

Reputation: 15079

Why isn't has_many working on these Mongoid models?

I have these models:

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

But when I try to add a store through feeds, I get these errors:

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

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

Upvotes: 0

Views: 267

Answers (1)

Jeremy Smith
Jeremy Smith

Reputation: 15079

Ah, silly me. These are operations on an instance not on a class.

Upvotes: 1

Related Questions