Skip to content

Commit

Permalink
filter types that have the relatedDocument option set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
ETLaurent committed Aug 24, 2023
1 parent 552a832 commit dd10feb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/apiRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ module.exports = self => {

return [ ...new Set(relatedTypes) ];

// TODO: do not include types that have the `relatedDocument = false`
// option in their module configuration
function searchRelationships(obj) {
const shouldRecurse = recursions <= maxRecursions;

if (obj.type === 'relationship') {
return obj.withType;
// Filter out types that has the `relatedDocument` option set to `false` in their module.
// Use `default-page` because this option is set on the page-type module,
// which does not actually exist inside `apos.modules`:
const module = obj.withType === '@apostrophecms/page'
? 'default-page'
: obj.withType;

return self.apos.modules[module].options.relatedDocument === false && obj.withType;
} else if (obj.type === 'array' || obj.type === 'object') {
recursions++;
return shouldRecurse && obj.schema.flatMap(searchRelationships);
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = self => {
// never be considered "related" to other pages simply because
// of navigation links, the feature is meant for pieces that feel more like
// part of the document being localized)
return related.filter(doc => self.apos.modules[doc.type].relatedDocument !== false);
return related.filter(doc => self.apos.modules[doc.type].options.relatedDocument !== false);
}
};
};

0 comments on commit dd10feb

Please sign in to comment.