Merge pull request #50 from strongloop/fix/prototype
Always call inherits to ensure prototypes are setup
This commit is contained in:
commit
efb5b36c84
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue