Merge pull request #91 from strongloop/bug/base-model

Fix base class not being actual base class
This commit is contained in:
Ritchie Martori 2013-12-09 17:19:38 -08:00
commit 2885d3c08f
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) { 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 to attach
try { try {

View File

@ -31,4 +31,25 @@ describe('loopback', function() {
assert.equal(Product.stats.shared, true); 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);
});
});
});
}); });