diff --git a/lib/model-builder.js b/lib/model-builder.js index 2b2bf733..a0668ad7 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -109,10 +109,16 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett buildSchema(className, properties); // every class can receive hash of data as optional param - var ModelClass = function ModelConstructor(data, schema) { + var ModelClass = function ModelConstructor(data, schema) { ModelBaseClass.apply(this, arguments); hiddenProperty(this, 'schema', schema || this.constructor.schema); }; + + // mix in EventEmitter + var events = new EventEmitter(); + ModelClass.on = events.on.bind(events); + ModelClass.once = events.once.bind(events); + ModelClass.emit = events.emit.bind(events); hiddenProperty(ModelClass, 'schema', schema); hiddenProperty(ModelClass, 'modelName', className); @@ -370,7 +376,7 @@ ModelBuilder.prototype.copyModel = function copyModel(Master) { */ function hiddenProperty(where, property, value) { Object.defineProperty(where, property, { - writable: false, + writable: true, enumerable: false, configurable: true, value: value