From 2f97ff1f93a122a169614d12f9025c17d141c478 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 15 Oct 2020 15:39:46 +0100 Subject: [PATCH] better error handling for missing model error (#8328) * Ammending commit Signed-off-by: Thomas Chezieres * ammending last commit Signed-off-by: Thomas Chezieres Co-authored-by: Thomas Chezieres Co-authored-by: Alexandre BODIN --- packages/strapi-utils/lib/models.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/strapi-utils/lib/models.js b/packages/strapi-utils/lib/models.js index 9df9b11ac6..c1e05ee58f 100644 --- a/packages/strapi-utils/lib/models.js +++ b/packages/strapi-utils/lib/models.js @@ -75,6 +75,13 @@ module.exports = { }); }); } else if (_.has(attribute, 'via') && _.has(attribute, 'collection')) { + if (!_.has(models, attribute.collection)) { + throw new Error( + `The collection \`${_.upperFirst( + attribute.collection + )}\` is missing from the ${attribute.plugin ? '(plugin - ' + attribute.plugin + ')' : ''} models` + ); + } const relatedAttribute = models[attribute.collection].attributes[attribute.via]; if (!relatedAttribute) {