mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
Fetch deep-nested embedded relationships
refs https://github.com/TryGhost/Ghost/pull/9426/files - when using `?include=foo` for a related model that itself normally has embedded relationships we need to add the nested relationship to the `include` param - eg. `/posts?include=authors,authors.roles` - this is necessary to ensure we don't introduce partial models into the Ember Data store by missing the embedded relationships on some requests
This commit is contained in:
parent
b79946979e
commit
8d8dbb7479
@ -115,17 +115,27 @@ export default BaseAdapter.extend({
|
|||||||
getEmbeddedRelations(store, modelName) {
|
getEmbeddedRelations(store, modelName) {
|
||||||
let model = store.modelFor(modelName);
|
let model = store.modelFor(modelName);
|
||||||
let ret = [];
|
let ret = [];
|
||||||
|
let embedded = [];
|
||||||
|
|
||||||
// Iterate through the model's relationships and build a list
|
// Iterate through the model's relationships and build a list
|
||||||
// of those that need to be pulled in via "include" from the API
|
// of those that need to be pulled in via "include" from the API
|
||||||
model.eachRelationship(function (name, meta) {
|
model.eachRelationship((name, meta) => {
|
||||||
if (meta.kind === 'hasMany'
|
if (
|
||||||
|
meta.kind === 'hasMany'
|
||||||
&& Object.prototype.hasOwnProperty.call(meta.options, 'embedded')
|
&& Object.prototype.hasOwnProperty.call(meta.options, 'embedded')
|
||||||
&& meta.options.embedded === 'always') {
|
&& meta.options.embedded === 'always'
|
||||||
|
) {
|
||||||
ret.push(name);
|
ret.push(name);
|
||||||
|
embedded.push([name, meta.type]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
embedded.forEach(([relName, modelName]) => {
|
||||||
|
this.getEmbeddedRelations(store, modelName).forEach((name) => {
|
||||||
|
ret.push(`${relName}.${name}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user