From 749a494e532b0e2a066ccbcbdbae1aed4d3c0751 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Wed, 11 Dec 2013 14:45:27 -0800 Subject: [PATCH] Always call inherits to ensure prototypes are setup --- lib/model-builder.js | 3 ++- test/model-definition.test.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/model-builder.js b/lib/model-builder.js index 89cd6793..dcbb3a99 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -158,10 +158,11 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett ModelClass[f] = EventEmitter.prototype[f].bind(events); } } - util.inherits(ModelClass, ModelBaseClass); hiddenProperty(ModelClass, 'modelName', className); } + util.inherits(ModelClass, ModelBaseClass); + // store class in model pool this.models[className] = ModelClass; diff --git a/test/model-definition.test.js b/test/model-definition.test.js index 3fed1eb8..c2bc5e53 100644 --- a/test/model-definition.test.js +++ b/test/model-definition.test.js @@ -5,6 +5,7 @@ var assert = require('assert'); var jdb = require('../'); var ModelBuilder = jdb.ModelBuilder; var DataSource = jdb.DataSource; +var Memory = require('../lib/connectors/memory'); var ModelDefinition = require('../lib/model-definition'); @@ -228,5 +229,25 @@ describe('ModelDefinition class', function () { done(); }); + it('should inherit prototype using option.base', function () { + var memory = new DataSource({connector: Memory}); + var modelBuilder = memory.modelBuilder; + var parent = memory.createModel('parent', {}, { + relations: { + children: { + type: 'hasMany', + model: 'anotherChild' + } + } + }); + var baseChild = modelBuilder.define('baseChild'); + baseChild.attachTo(memory); + // the name of this must begin with a letter < b + // for this test to fail + var anotherChild = baseChild.extend('anotherChild'); + + assert(anotherChild.prototype instanceof baseChild); + }); + });