diff --git a/lib/application.js b/lib/application.js index 9d7e462c..3d64d48d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -138,6 +138,9 @@ app.model = function(Model, config) { this.models().push(Model); if (isPublic && Model.sharedClass) { + this.remotes().defineObjectType(Model.modelName, function(data) { + return new Model(data); + }); this.remotes().addClass(Model.sharedClass); if (Model.settings.trackChanges && Model.Change) { this.remotes().addClass(Model.Change.sharedClass); @@ -316,8 +319,10 @@ app.enableAuth = function(options) { g.f('Authentication requires model %s to be defined.', m)); } - if (m.dataSource || m.app) return; + if (Model.dataSource || Model.app) return; + // Find descendants of Model that are attached, + // for example "Customer" extending "User" model for (var name in appModels) { var candidate = appModels[name]; var isSubclass = candidate.prototype instanceof Model; diff --git a/lib/model.js b/lib/model.js index 6d24e095..1926628b 100644 --- a/lib/model.js +++ b/lib/model.js @@ -134,11 +134,6 @@ module.exports = function(registry) { remotingOptions ); - // setup a remoting type converter for this model - RemoteObjects.convert(typeName, function(val) { - return val ? new ModelCtor(val) : val; - }); - // support remoting prototype methods ModelCtor.sharedCtor = function(data, id, fn) { var ModelCtor = this; diff --git a/package.json b/package.json index 2b059745..3a32789a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "ejs": "^2.3.1", "express": "^4.14.0", "inflection": "^1.6.0", - "loopback-connector-remote": "^2.0.0-alpha.1", + "loopback-connector-remote": "^2.0.0-alpha.2", "loopback-datasource-juggler": "^3.0.0-alpha.7", "isemail": "^1.2.0", "loopback-phase": "^1.2.0", @@ -55,7 +55,7 @@ "serve-favicon": "^2.2.0", "stable": "^0.1.5", "strong-globalize": "^2.6.2", - "strong-remoting": "^3.0.0-alpha.5", + "strong-remoting": "^3.0.0-alpha.6", "uid2": "0.0.3", "underscore.string": "^3.0.3" }, diff --git a/test/relations.integration.js b/test/relations.integration.js index e0f1c840..2d50313d 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -656,6 +656,9 @@ describe('relations - integration', function() { describe('hasAndBelongsToMany', function() { beforeEach(function defineProductAndCategoryModels() { + // Disable "Warning: overriding remoting type product" + this.app.remotes()._typeRegistry._options.warnWhenOverridingType = false; + var product = app.registry.createModel( 'product', { id: 'string', name: 'string' } diff --git a/test/remote-connector.test.js b/test/remote-connector.test.js index f2c50e56..231c2617 100644 --- a/test/remote-connector.test.js +++ b/test/remote-connector.test.js @@ -15,7 +15,10 @@ describe('RemoteConnector', function() { beforeEach: function(done) { var test = this; remoteApp = loopback(); - remoteApp.set('remoting', { errorHandler: { debug: true, log: false }}); + remoteApp.set('remoting', { + errorHandler: { debug: true, log: false }, + types: { warnWhenOverridingType: false }, + }); remoteApp.use(loopback.rest()); remoteApp.listen(0, function() { test.dataSource = loopback.createDataSource({ @@ -51,6 +54,9 @@ describe('RemoteConnector', function() { beforeEach(function(done) { var test = this; remoteApp = this.remoteApp = loopback(); + remoteApp.set('remoting', { + types: { warnWhenOverridingType: false }, + }); remoteApp.use(loopback.rest()); var ServerModel = this.ServerModel = loopback.PersistedModel.extend('TestModel'); diff --git a/test/user.test.js b/test/user.test.js index a13d3c7b..8e6055e1 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -70,7 +70,6 @@ describe('User', function() { app.enableAuth({ dataSource: 'db' }); app.use(loopback.token({ model: AccessToken })); app.use(loopback.rest()); - app.model(User); User.create(validCredentials, function(err, user) { if (err) return done(err);