Skip to content

Commit

Permalink
Merge pull request #1306 from balderdashy/metaAttribute
Browse files Browse the repository at this point in the history
Meta attribute property
  • Loading branch information
particlebanana committed Mar 16, 2016
2 parents f0fd39a + 35e1928 commit 2a8daf3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/waterline.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Waterline.prototype.initialize = function(options, cb) {
// Allow collections to be passed in to the initialize method
if (options.collections) {
for (var collection in options.collections) {
this.loadCollection(_.cloneDeep(options.collections[collection]));
this.loadCollection(options.collections[collection]);
}

// Remove collections from the options after they have been loaded
Expand Down Expand Up @@ -160,6 +160,7 @@ Waterline.prototype.initialize = function(options, cb) {

schemas[collection.identity] = collection;
schemas[collection.identity].definition = schema;
schemas[collection.identity].attributes = collection._attributes;
schemas[collection.identity].meta = meta;
});

Expand Down Expand Up @@ -191,7 +192,7 @@ Waterline.prototype.initialize = function(options, cb) {
identity = self.collections[coll].__proto__.tableName;
}

usedSchemas[identity] = results.buildCollectionSchemas[coll];
usedSchemas[identity] = _.pick(results.buildCollectionSchemas[coll], ['definition', 'attributes', 'meta']);
});

// Call the registerConnection method
Expand Down
2 changes: 1 addition & 1 deletion lib/waterline/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Core = module.exports = function(options) {

// Set Defaults
this.adapter = this.adapter || {};
this._attributes = _.clone(this.attributes);
this._attributes = this.attributes;
this.connections = this.connections || {};

this.defaults = _.merge(COLLECTION_DEFAULTS, this.defaults);
Expand Down
29 changes: 26 additions & 3 deletions lib/waterline/core/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,32 @@ Validator.prototype.initialize = function(attrs, types, defaults) {

defaults = defaults || {};

this.reservedProperties = ['defaultsTo', 'primaryKey', 'autoIncrement', 'unique', 'index', 'collection', 'dominant', 'through',
'columnName', 'foreignKey', 'references', 'on', 'groupKey', 'model', 'via', 'size',
'example', 'validationMessage', 'validations', 'populateSettings', 'onKey', 'protected'];
// These properties are reserved and may not be used as validations
this.reservedProperties = [
'defaultsTo',
'primaryKey',
'autoIncrement',
'unique',
'index',
'collection',
'dominant',
'through',
'columnName',
'foreignKey',
'references',
'on',
'groupKey',
'model',
'via',
'size',
'example',
'validationMessage',
'validations',
'populateSettings',
'onKey',
'protected',
'meta'
];


if (defaults.ignoreProperties && Array.isArray(defaults.ignoreProperties)) {
Expand Down
9 changes: 8 additions & 1 deletion test/unit/core/core.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ describe('Core Validator', function() {
last_name: {
type: 'string',
required: true,
defaultsTo: 'Smith'
defaultsTo: 'Smith',
meta: {
foo: 'bar'
}
}
}
});
Expand Down Expand Up @@ -59,6 +62,10 @@ describe('Core Validator', function() {
assert(!person._validator.validations.last_name.defaultsTo);
});

it('should ignore the meta key', function() {
assert(!person._validator.validations.last_name.meta);
});

});


Expand Down

0 comments on commit 2a8daf3

Please sign in to comment.