Im working in Ember 3.1 and JSON:API format to get data from backend.
My models are something like follow:
// Continent model
export default DS.Model.extend({
name: attr('string'),
countries: hasMany('countries'),
});
// Country model
export default DS.Model.extend({
name: attr('string'),
president: belongsTo('president'),
regions: hasMany('region')
});
// President model
export default DS.Model.extend({
name: attr('string')
});
// Region model
export default DS.Model.extend({
name: attr('string')
});
The way a fetch my models are:
fetchInformation: task(function* () {
yield get(this, 'store')
.findRecord('continent', continent,
{
include: 'countries,'
+ 'countries.president,'
+ 'countries.regions'
}
).then((continent) => {
get(continent, 'countries.firstObject') // This one gets resolved properly
get(continent, 'countries.firstObject.president') // Get Proxy object
get(continent, 'countries.firstObject.regions.firstObject') // Get Proxy object
})
I thought that by using 'include' and the server replying as JSON:API specs, I would have access to all those properties.
To me it seems that those nested relationships needs to get resolved somehow.
What am I missing? Is there any way to work easily with nested models?
Aucun commentaire:
Enregistrer un commentaire