Always call inherits to ensure prototypes are setup

This commit is contained in:
Ritchie Martori 2013-12-11 14:45:27 -08:00
parent e950264edd
commit 749a494e53
2 changed files with 23 additions and 1 deletions

View File

@ -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;

View File

@ -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);
});
});