Skip to content

Exposing a List of Entities #186

Open
@Linell

Description

@Linell

So I have an Employee entity that looks something like this.

class Employee::Entity < Grape::Entity
  expose :id, :name, :company
end

The Employee has tons of clock ins to the timecard system. The entity for a Clockin is something like:

class Clockin::Entity < Grape::Entity
  expose :id, :year, :date, :code, :description
end

Displaying all of the clock ins for an employee is easy enough. How would I go about segregating them by year, though?

My first thought was adding something like this to the Employee entity

expose :clockins do |employee, options|
  employee.clockins.group_by { |c| c[:year] }
end

That does get the correct data, but it's not presented correctly.

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