better error handling for missing model error (#8328)

* Ammending commit

Signed-off-by: Thomas Chezieres <tchezieres@MacBook-Pro.lan>

* ammending last commit

Signed-off-by: Thomas Chezieres <tchezieres@MacBook-Pro.lan>

Co-authored-by: Thomas Chezieres <tchezieres@MacBook-Pro.lan>
Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
This commit is contained in:
Thomas 2020-10-15 15:39:46 +01:00 committed by GitHub
parent 1186d6a2ec
commit 2f97ff1f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {