diff --git a/lib/datasource.js b/lib/datasource.js index 549e9734..2a8b7b35 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -498,6 +498,7 @@ DataSource.prototype.setupDataAccess = function (modelClass, settings) { // Set the default id type from connector's ability var idType = this.connector.getDefaultIdType() || String; idProp.type = idType; + modelClass.definition.rawProperties[idName].type = idType; modelClass.definition.properties[idName].type = idType; if (settings.forceId) { modelClass.validatesAbsenceOf(idName, {if: 'isNewRecord'}); diff --git a/lib/model-builder.js b/lib/model-builder.js index 89b5f765..b36e4d41 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -377,7 +377,13 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett continue; } if (subclassProperties[key] === undefined) { - subclassProperties[key] = properties[key]; + var baseProp = properties[key]; + var basePropCopy = baseProp; + if (baseProp && typeof baseProp === 'object') { + // Deep clone the base prop + basePropCopy = mergeSettings(null, baseProp); + } + subclassProperties[key] = basePropCopy; } } diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index b5d0c658..14d9892b 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -691,6 +691,22 @@ describe('Load models with base', function () { Customer.definition.properties.name.should.have.property('type', String); }); + it('should inherit properties by clone from base option', function () { + var ds = new ModelBuilder(); + + var User = ds.define('User', {name: String}); + + var Customer1 = ds.define('Customer1', {vip: Boolean}, {base: 'User'}); + var Customer2 = ds.define('Customer2', {vip: Boolean}, {base: 'User'}); + + Customer1.definition.properties.should.have.property('name'); + Customer2.definition.properties.should.have.property('name'); + Customer1.definition.properties.name.should.not.be.equal( + Customer2.definition.properties.name); + Customer1.definition.properties.name.should.eql( + Customer2.definition.properties.name); + }); + it('should revert properties from base model', function() { var ds = new ModelBuilder();