diff --git a/lib/waterline-schema/schema.js b/lib/waterline-schema/schema.js index 9f100a4..9bdae36 100644 --- a/lib/waterline-schema/schema.js +++ b/lib/waterline-schema/schema.js @@ -132,6 +132,9 @@ module.exports = function schemaBuilder(collections) { tableName: collection.tableName, datastore: collection.datastore || collection.connection, attributes: _.merge({}, collection.attributes), + //Allow the attribute properties to be flexibly defined, + //e.g. phone: {type:"string", isMobilePhone:true, isXYZProperty:false} + attributeWhitelist: collection.attributeWhitelist && collection.attributeWhitelist === "flexible" || "strict", // The schema piece will be transformed along the way to reflect the // underlying datastructure. i.e. expanding out associations into foreign // keys, etc. @@ -234,11 +237,13 @@ module.exports = function schemaBuilder(collections) { // ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝ ┴ ┴└─└─┘┴ └─┘┴└─ ┴ ┴└─┘└─┘ // If the attribute contains a property that isn't whitelisted, then return // an error. - _.each(attribute, function parseProperties(propertyValue, propertyName) { - if (_.indexOf(validProperties, propertyName) < 0) { - throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The property `' + propertyName + '` isn\'t a recognized property.')); - } - }); + if (schemaCollection.attributeWhitelist === "strict") { + _.each(attribute, function parseProperties(propertyValue, propertyName) { + if (_.indexOf(validProperties, propertyName) < 0) { + throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The property `' + propertyName + '` isn\'t a recognized property.')); + } + }); + } // ╦ ╦╔═╗╦ ╦╔╦╗╔═╗╔╦╗╔═╗ ┌─┐┬ ┬ ┌─┐┬ ┬╔╗╔┬ ┬┬ ┬