i have Trip model which has destinations defined like that:
class Trip < ActiveRecord::Base
...
has_and_belongs_to_many :destinations, join_table: :trips_destinations
...
end
What I want to do is to expose the trip information included the associated destinations. I defined this response entity for the destinations:
module Services
module Trips
class DestinationResponseEntity < Grape::Entity
expose :id
expose :name
end
end
end
And the trip destination entity is this:
module Services
module Trips
class TripResponseEntity < Grape::Entity
expose :id
expose :title
expose :duration
expose :total_price
expose :description
expose :destinations, using: Trips::DestinationResponseEntity
expose :photo
end
end
end
I'm presenting the result in that way:
present trip, :with => Trips::TripResponseEntity
But the response of the service returns always an empty destination array.
[{"id":3,"title":"Islandhopping in Thailand","duration":14,"total_price":3450,"description":"Relax under swaying palm trees then jump into crystal-clear waters",**"destinations":[]**,"photo":"http://s3.amazonaws.com/ntradadevelopment/images/trips/3/original/thailand.jpeg"]
In the console I can see all the destinations associated with the trip properly. Any clue of what could be causing the issue is really appreciated.