diff --git a/lib/dao.js b/lib/dao.js index eb779979..b3115126 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -162,6 +162,7 @@ DataAccessObject.create = function (data, callback) { DataAccessObject.create.shared = true; DataAccessObject.create.accepts = {arg: 'data', type: 'object'}; DataAccessObject.create.returns = {arg: 'data', type: 'object'}; +DataAccessObject.create.http = {verb: 'post', path: '/'}; function stillConnecting(schema, obj, args) { if (schema.connected) return false; // Connected @@ -532,7 +533,6 @@ DataAccessObject.prototype.save = function (options, callback) { DataAccessObject.prototype.save.shared = true; DataAccessObject.prototype.save.returns = {arg: 'obj', type: 'object'}; DataAccessObject.prototype.save.http = [ - {verb: 'post', path: '/'}, {verb: 'put', path: '/'} ]; diff --git a/lib/model-builder.js b/lib/model-builder.js index a0668ad7..75da749c 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -111,7 +111,9 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett // every class can receive hash of data as optional param var ModelClass = function ModelConstructor(data, schema) { ModelBaseClass.apply(this, arguments); - hiddenProperty(this, 'schema', schema || this.constructor.schema); + if(!this.schema) { + hiddenProperty(this, 'schema', schema || this.constructor.schema); + } }; // mix in EventEmitter @@ -198,8 +200,14 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett s[key] = settings[key]; } }); - - return schema.define(className, p, s, ModelClass); + + var c = schema.define(className, p, s, ModelClass); + + if(typeof c.setup === 'function') { + c.setup.call(c); + } + + return c; } ModelClass.registerProperty = function (attr) { diff --git a/lib/model.js b/lib/model.js index fd8692e0..87c41939 100644 --- a/lib/model.js +++ b/lib/model.js @@ -34,7 +34,10 @@ ModelBaseClass.prototype._initProperties = function (data, applySetters) { var self = this; var ctor = this.constructor; - var ds = ctor.schema.definitions[ctor.modelName]; + var ds = { + properties: ctor.properties, + setters: ctor.settings + }; var properties = ds.properties; data = data || {}; @@ -133,7 +136,7 @@ ModelBaseClass.defineProperty = function (prop, params) { }; ModelBaseClass.whatTypeName = function (propName) { - var prop = this.schema.definitions[this.modelName].properties[propName]; + var prop = this.properties[propName]; if (!prop || !prop.type) { throw new Error('Undefined type for ' + this.modelName + ':' + propName); }