Fix base class not being actual base class
This commit is contained in:
parent
2efd2b1e2f
commit
e7cc30ee03
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue