Fix base class not being actual base class

This commit is contained in:
Ritchie Martori 2013-12-09 17:11:01 -08:00
parent 2efd2b1e2f
commit e7cc30ee03
2 changed files with 31 additions and 1 deletions

View File

@ -113,7 +113,16 @@ loopback.createDataSource = function (name, options) {
*/
loopback.createModel = function (name, properties, options) {
var model = loopback.Model.extend(name, properties, options);
options = options || {};
var BaseModel = options.base || options.super;
if(typeof BaseModel === 'string') {
BaseModel = loopback.getModel(BaseModel);
}
BaseModel = BaseModel || loopback.Model;
var model = BaseModel.extend(name, properties, options);
// try to attach
try {

View File

@ -31,4 +31,25 @@ describe('loopback', function() {
assert.equal(Product.stats.shared, true);
});
});
describe('loopback.createModel(name, properties, options)', function () {
describe('options.base', function () {
it('should extend from options.base', function () {
var MyModel = loopback.createModel('MyModel', {}, {
foo: {
bar: 'bat'
}
});
var MyCustomModel = loopback.createModel('MyCustomModel', {}, {
base: 'MyModel',
foo: {
bat: 'baz'
}
});
assert(MyCustomModel.super_ === MyModel);
assert.deepEqual(MyCustomModel.settings.foo, { bar: 'bat', bat: 'baz' });
assert(MyCustomModel.super_.modelName === MyModel.modelName);
});
});
});
});