waterline-schema
Advanced tools
Comparing version 1.0.0-21 to 1.0.0-22
@@ -62,12 +62,16 @@ // ██████╗ ██╗ ██╗██╗██╗ ██████╗ | ||
// exists on the other model. | ||
if (_.has(attributeVal, 'via') && !relatedModel.schema[attributeVal.via]) { | ||
throw flaverr({ name: 'userError' }, new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to an attribute using `via` on the `' + relatedModel.identity + '` model that doesn\'t exist.')); | ||
if (_.has(attributeVal, 'via')) { | ||
if (!relatedModel.schema[attributeVal.via]) { | ||
throw flaverr({ name: 'userError' }, new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to an attribute using `via` on the `' + relatedModel.identity + '` model that doesn\'t exist.')); | ||
} | ||
// Check if it's a foreign key. If so this is a one-to-many relationship and no join table is needed. | ||
if (_.has(relatedModel.schema[attributeVal.via], 'foreignKey')) { | ||
return; | ||
} | ||
// Otherwise check that it points back to this model. | ||
if (!relatedModel.schema[attributeVal.via].collection || relatedModel.schema[attributeVal.via].collection !== collectionName) { | ||
throw flaverr({ name: 'userError' }, new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to an attribute using `via` on the `' + relatedModel.identity + '` model that doesn\'t point back to `' + relatedModel.identity + '`.')); | ||
} | ||
} | ||
// If a `via` is used, check if it's a foreign key. If so this is a one-to-many | ||
// relationship and no join table is needed. | ||
if (_.has(attributeVal, 'via') && _.has(relatedModel.schema[attributeVal.via], 'foreignKey')) { | ||
return; | ||
} | ||
// If no via is specified, a name needs to be created for the other column | ||
@@ -74,0 +78,0 @@ // in the join table. Use the attribute key and the associated collection name |
{ | ||
"name": "waterline-schema", | ||
"description": "The core schema builder used in the Waterline ORM.", | ||
"version": "1.0.0-21", | ||
"version": "1.0.0-22", | ||
"dependencies": { | ||
@@ -6,0 +6,0 @@ "@sailshq/lodash": "^3.10.2", |
152130
3007