Skip to content

Commit

Permalink
Merge branch 'v0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Feb 3, 2014
2 parents dde743c + 64ff2f6 commit 50b51af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions lib/index.js
Expand Up @@ -50,7 +50,13 @@ var util = require('util') // Native Node util module
, query // Lazy-load query; it depends on model/index
, association; // Lazy-load query; it depends on model/index

var _foreignKeyCreators = [];
var _foreignKeyCreators = []
, _systemProperties = {
id: true
, type: true
, createdAt: true
, updatedAt: true
};

utils.mixin(model, new (function () {

Expand Down Expand Up @@ -147,7 +153,7 @@ utils.mixin(model, new (function () {
this.toJSON = function (options) {
var self = this
, opts = options || {}
, whitelist = ['id', 'type', 'createdAt', 'updatedAt']
, whitelist = Object.keys(_systemProperties)
, obj = {}
, reg = model.descriptionRegistry[this.type]
, properties = reg.properties
Expand Down Expand Up @@ -913,9 +919,18 @@ model.ModelDefinitionBase = function (name) {
this.adapter = adapter;
};

this.property = function (name, datatype, o) {
this.property = function (name, datatype, options) {
var opts = options || {};

// Don't allow users to define properties with the same
// name as magical system properties
if (!opts.isSystem && _systemProperties[name]) {
throw new Error('You cannot define the property "' + name +
'" on a model, as it\'s a reserved system-property name.');
}

reg[this.name].properties[name] =
new model.PropertyDescription(name, datatype, o);
new model.PropertyDescription(name, datatype, opts);
};

this.defineProperties = function (obj) {
Expand Down Expand Up @@ -979,8 +994,8 @@ model.ModelDefinitionBase = function (name) {

// Add the base model properties -- these should not be handled by user input
if (model.useTimestamps) {
this.property('createdAt', 'datetime');
this.property('updatedAt', 'datetime');
this.property('createdAt', 'datetime', {isSystem: true});
this.property('updatedAt', 'datetime', {isSystem: true});
}

['hasMany', 'hasOne', 'belongsTo'].forEach(function (assnKey) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"leveldb",
"sqlite"
],
"version": "0.5.1",
"version": "0.5.2",
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
"main": "./lib/index.js",
"scripts": {
Expand Down

0 comments on commit 50b51af

Please sign in to comment.