ModelQuery: throw an error when fed with nonexistent relation

This commit is contained in:
Alice Gaudon 2020-07-28 10:33:17 +02:00
parent df651f2661
commit 97b2d3b94c

View File

@ -183,6 +183,7 @@ export default class ModelQuery<M extends Model> {
// Eager loading init map // Eager loading init map
for (const relation of this.relations) { for (const relation of this.relations) {
if (model[relation] === undefined) throw new Error(`Relation ${relation} doesn't exist on ${model.constructor.name}.`);
relationMap[relation].push(model[relation]); relationMap[relation].push(model[relation]);
} }
} }