The requirements of my project are now forcing me to passing parameters to nested entities. I have an entity A and an entity B that show some information and needs the A identifier on the system to build them.
module Services
module Trips
class TripPreviewResponseEntity < Grape::Entity
expose :id
expose :title
expose :duration
expose :total_price
expose :description
expose :details
expose :destinations, using: Destinations::DestinationResponseEntity
end
end
end
In the example above I want to do something like that:
expose :destinations, using: Destinations::DestinationResponseEntity, :trip_id => object.id
And in the nested Entity use the trip_id parameter option in this way:
expose :trip_info do |item,options|
item.show(options[:trip_id])
end
But it's failing saying that object is not defined into the entity. Is there a way to perform this? Any idea?
module Services
module Trips
class TripPreviewResponseEntity < Grape::Entity
expose :id
expose :title
expose :duration
expose :total_price
expose :description
expose :details
expose :destinations do |trip, _options|
DestinationResponseEntity.represent(trip.destinations, trip_id: trip.id)
end
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With