Good day!
Just want to ask on how to create a JSONAPISerializer for an ajax call? From what I understand on the docs. I must first create a model before I can make a JSONAPISerializer. But I need to call a custom endpoint that is not listed as my model.
My goal is to pushPayload
all the sideloaded data coming from my endpoint. but the problem is :
{
"data":[
{
"type":"promotions-verify", <----- it's not an actual model
"attributes":{
"cart-items-discount-in-cents":21900
},
"relationships":{...}, <---- sideloaded data that I want to push on ember-data
}],
"included": [] <---- sideloaded data that I want to push on ember-data
}
Is there a reason you can't make a model for
promotions-verify
? That would be the cleanest way to implement loading in the side-loaded data, since Ember would handle much of the serialization/pushing to the store for you.If that isn't possible and you make an ajax request, you may need to map the
relationships
andincluded
payloads to match up with one another (Lodash_.map()
could work well for this). Then you can manually push that data (pushPayload
) to the Ember store, while ensuring that the items you're pushing also have models and serializers.Also, I'm not sure if this was accidental, but your example payload doesn't conform to JSON API standards – the
relationships
object should be nested withindata
. This will affect how Ember serializes the data, as it's expecting: