The API endpoint I'm working with is returning data that has multiple nested relationships inside it, and I am using normalizeResponse()
within DS.JSONAPISerializer
to massage it into something that is fully JSON-API compliant.
The ember inspector shows that all data gets placed within its respective container correctly. The link between the top-level model and its hasMany
child does work, but the link between the nested models does not work. I verify this by navigating within the inspector to the nested model's child model, clicking on it, and observing that its 'content' property is null.
First, take a look at how my models are set up:
// models/search.js
// i am able to browse from the search model to children with success
export default DS.Model.extend({
articles: DS.hasMany('article'),
});
// models/article.js
// i CANNOT browse from an article down to its digest in ember inspector
export default DS.Model.extend({
search: DS.belongsTo('search'),
type: DS.attr(),
created: DS.attr(),
updated: DS.attr(),
digest: DS.belongsTo('digest'),
});
// models/digest.js
export default DS.Model.extend({
title: DS.attr(),
desc: DS.attr(),
date: DS.attr(),
article: DS.belongsTo('article'),
});
Now, here's my modified JSON after my functions inside normalizeResponse
complete. AFTER returning this data from normalizeResponse
, the "digest" object under the parent "relationships" object disappears. Is there something wrong with my JSON? I've tried so many permutations of this with no success, and I am pretty sure this matches the JSON-API spec for Compound Documents.
{"data":{
"type":"searches",
"id":"17482738723",
"attributes":{
},
"relationships":{
"articles":{
"data":[
{
"type":"articles",
"id":"19988"
},
{
"type":"articles",
"id":"19989"
},
]
},
"digest":{
"data":[
{
"type":"digest",
"id":"19988_digest"
},
{
"type":"digest",
"id":"19989_digest"
},
]
}
}
},
"included":[
{
"id":"19988",
"type":"articles",
"attributes":{
"type": "internal",
"created":"2016-09-27T00:13:11.000Z",
"updated":"2016-09-27T00:13:11.000Z",
}
},
{
"id":"19988_digest",
"type":"digest",
"attributes":{
"title":null,
"desc":"four five six",
}
},
{
"id":"19989",
"type":"articles",
"attributes":{
"type": "internal",
"created":"2016-09-27T00:13:11.000Z",
"updated":"2016-09-27T00:13:11.000Z",
}
},
{
"id":"19989_digest",
"type":"digest",
"attributes":{
"title":"one two three",
"desc":null,
}
},
]
}
Aucun commentaire:
Enregistrer un commentaire