Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/waterline-schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.'));
}
});
}


// ╦ ╦╔═╗╦ ╦╔╦╗╔═╗╔╦╗╔═╗ ┌─┐┬ ┬ ┌─┐┬ ┬╔╗╔┬ ┬┬ ┬
Expand Down