ruby-on-railsmongoidmongoid3

how include embedded Document in rails only query


The model Claim consists of a large number of fields. In claim controller index action querying claims with the only function, fields that are printed in the index list are querying from the db

@claims = @claims.only(:nice_id, :brand_id, etc.. :status).desc(:_id)

The class 'Document' embedded in claims, many document embedded in claims.

I need to include documents in the claim to resultant set. what changes are needed to make in my query?

Used Mongoid in place of Active Model,

mongoid version 3, rails version 3.2


Solution

  • Well, for me, on mongoid 3, adding the association name or its alias (stored_as) (if any) to only works:

    @claims = @claims.only(:nice_id, :brand_id, ..., :documents).desc(:_id)