From 1492e2d431e1b1c5ee6485b71953dc295a958507 Mon Sep 17 00:00:00 2001 From: Rob Gietema Date: Mon, 25 Mar 2024 10:03:51 +0100 Subject: [PATCH] Fix related items in get call. --- CHANGELOG.md | 1 + src/models/document/document.js | 7 ++++++- src/routes/content/content.js | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7a9fc9..014dec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - Fix project vocabularies @robgietema - Fix password reset link @robgietema - Fix serving videos @robgietema +- Fix related items in get call @robgietema ### Internal diff --git a/src/models/document/document.js b/src/models/document/document.js index 0c4d53f..dd50c0f 100644 --- a/src/models/document/document.js +++ b/src/models/document/document.js @@ -399,7 +399,12 @@ export class Document extends Model { const relationListFields = this._type.getFactoryFields('Relation List'); mapSync(relationListFields, async (field) => { // Check if related documents - if (isArray(json[field]) && json[field].length > 0) { + if ( + isArray(json[field]) && + json[field].length > 0 && + this._relationLists && + this.relationLists[field] + ) { json[field] = this._relationLists[field].map((document) => ({ '@id': document.path, UID: document.uuid, diff --git a/src/routes/content/content.js b/src/routes/content/content.js index 69984ad..7604aa2 100644 --- a/src/routes/content/content.js +++ b/src/routes/content/content.js @@ -295,7 +295,11 @@ export default [ if (req.document._children) { await Promise.all( req.document._children.map( - async (child) => await child.fetchRelated('_catalog', trx), + async (child) => + await Promise.all( + child.fetchRelated('_catalog', trx), + child.fetchRelationLists(trx), + ), ), ); }