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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.