ruby-grape / ruby-grape/grape-entity
Getting separate queries for each attribute of an entity
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
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:

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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CustomerEntity exposure list and the Users::Authentication endpoint, especially the present(u) call, and reproduce the response while watching the query log. Trace how each exposed attribute is resolved and compare the observed queries with the entity representation; done means identifying the cause and establishing the expected query behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100