Hi there,
Is there a preferred method to combine multiple models of different types in a collection?
I have two models, Inspection and Event, and need to return those as a single collection. I was expecting that when calling render jsonapi: models, that it would automatically pick the proper serializer based on the type of the model but it blows up.
Currently, I'm manually handling the process with this but it feels messy:
inspections = load_inspections
events = load_events
serialized_inspections = Api::V1::Mobile::InspectionSerializer.new(inspections).serializable_hash
serialized_events = Api::V1::Mobile::EventSerializer.new(events).serializable_hash
eventables = { data: serialized_events[:data] + serialized_inspections[:data] }
render json: eventables.to_json, content_type: 'application/vnd.api+json'
In a perfect world, I'd love to be able to do something like:
inspections = load_inspections
events = load_events
render jsonapi: inspections + events
Thanks and apologies in advance if I'm missing something obvious!
Hi there,
Is there a preferred method to combine multiple models of different types in a collection?
I have two models,
InspectionandEvent, and need to return those as a single collection. I was expecting that when callingrender jsonapi: models, that it would automatically pick the proper serializer based on the type of the model but it blows up.Currently, I'm manually handling the process with this but it feels messy:
In a perfect world, I'd love to be able to do something like:
Thanks and apologies in advance if I'm missing something obvious!