Skip to content

Always expose with the default entity #185

Open
@waynn

Description

@waynn

I'm using grape and grape-entity in a Rails 4.2.1 project, and I'm running into a weird error with presenting using the right model.

According to the documentation, organizing my entities within each model results in this:

Grape will automatically detect the Entity class and use it to present your models.

In addition, the documentation also says:

By default every object of a collection is wrapped into an instance of your Entity class.

Here's the code I have now.

class User < ActiveRecord::Base
  class Entity < Grape::Entity
    expose :id, :name
    expose :addresses
  end
end

class Address < ActiveRecord::Base
  class Entity < Grape::Entity
    expose :id, :street1
  end
end

If I don't do expose :addresses, with: Address:Entity, it doesn't work, and still exposes all the fields of the address. Any reason it's not automatically detecting the correct entity?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions