Reputation: 1876
I have a couple mongoid models:
class Album
include Mongoid::Document
field :name, type: String
embedded_in :band
end
class Band
include Mongoid::Document
field :name, type: String
embeds_many :albums
end
And I'm trying to get inherited_resources to include the embedded albums in the json for bands, like so:
class BandsController < InheritedResources::Base
respond_to :html, :xml, :json
def permitted_params
params.permit!
end
protected
def collection
@bands ||= end_of_association_chain.includes(:albums)
end
end
But I get the following error when trying to retrieve the list of bands:
undefined method `eager_load' for Mongoid::Relations::Embedded::Many:Class
Any idea what I might be doing wrong?
Upvotes: 0
Views: 1405
Reputation: 12138
I am pretty much sure the error here is because you are overwriting collection
method. collection is an internal method that mongoid uses to do operations in the collection, so I guess if you overwrite it would cause some conflicts.
Upvotes: 2