grape-entity icon indicating copy to clipboard operation
grape-entity copied to clipboard

Getting separate queries for each attribute of an entity

Open ciaoben opened this issue 8 years ago • 1 comments

I am wondering why I am getting a separate query for each attribute of my entity.

For example, here I am asking for a CustomerEntity and it has more than 40 exposed attributes, and it seems that grape entity ask for each attribute with a separate query:

schermata 2017-02-02 alle 12 42 41

My entity is:

class CustomerEntity < Grape::Entity
    expose :is_wholesale
    expose :catch_all
    expose :max_managers
    expose :max_customizations
    expose :max_mailing_lists
    expose :max_email_quota
    expose :max_email_accounts_archive
    expose :max_email_accounts
    expose :max_domains
    expose :expiration
    expose :billing
    expose :is_reseller
    expose :status_detail
    expose :status
    expose :code
    expose :company
    expose :lastname
    expose :firstname
    # authentication
    expose :fakefield2
    expose :fakefield
    expose :fakefield3
    expose :fakefield4
    expose :fakefield5
    expose :email_address
    expose :language
    expose :type
end

and I am calling in my endpoint with:

class Users::Authentication < Grape::API
    represent Customer, with: CustomerEntity

   get do
      present(u)
   end

Am I doing something wrong?

ciaoben avatar Feb 02 '17 11:02 ciaoben

@ciaoben … please can you provide a Gist, or a Spec, where the behavior would be reproduced? without it, it is pretty difficult to investigate … thanks

LeFnord avatar Feb 06 '17 09:02 LeFnord