From e7cc30ee036b95c7a705b016839cb513381407fb Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 9 Dec 2013 17:11:01 -0800 Subject: [PATCH] Fix base class not being actual base class --- lib/loopback.js | 11 ++++++++++- test/loopback.test.js | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/loopback.js b/lib/loopback.js index e519b05b..8adffd87 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -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 { diff --git a/test/loopback.test.js b/test/loopback.test.js index cba3d425..ebbbee21 100644 --- a/test/loopback.test.js +++ b/test/loopback.test.js @@ -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); + }); + }); + }); });