Skip to content

Commit 252b6f4

Browse files
authored
Merge pull request #2696 from strongloop/feature/coercion-overhaul
Use strong-remoting's new TypeRegistry
2 parents f5acf6a + 6e1defc commit 252b6f4

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

lib/application.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ app.model = function(Model, config) {
138138
this.models().push(Model);
139139

140140
if (isPublic && Model.sharedClass) {
141+
this.remotes().defineObjectType(Model.modelName, function(data) {
142+
return new Model(data);
143+
});
141144
this.remotes().addClass(Model.sharedClass);
142145
if (Model.settings.trackChanges && Model.Change) {
143146
this.remotes().addClass(Model.Change.sharedClass);
@@ -316,8 +319,10 @@ app.enableAuth = function(options) {
316319
g.f('Authentication requires model %s to be defined.', m));
317320
}
318321

319-
if (m.dataSource || m.app) return;
322+
if (Model.dataSource || Model.app) return;
320323

324+
// Find descendants of Model that are attached,
325+
// for example "Customer" extending "User" model
321326
for (var name in appModels) {
322327
var candidate = appModels[name];
323328
var isSubclass = candidate.prototype instanceof Model;

lib/model.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ module.exports = function(registry) {
134134
remotingOptions
135135
);
136136

137-
// setup a remoting type converter for this model
138-
RemoteObjects.convert(typeName, function(val) {
139-
return val ? new ModelCtor(val) : val;
140-
});
141-
142137
// support remoting prototype methods
143138
ModelCtor.sharedCtor = function(data, id, fn) {
144139
var ModelCtor = this;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"ejs": "^2.3.1",
4747
"express": "^4.14.0",
4848
"inflection": "^1.6.0",
49-
"loopback-connector-remote": "^2.0.0-alpha.1",
49+
"loopback-connector-remote": "^2.0.0-alpha.2",
5050
"loopback-datasource-juggler": "^3.0.0-alpha.7",
5151
"isemail": "^1.2.0",
5252
"loopback-phase": "^1.2.0",
@@ -55,7 +55,7 @@
5555
"serve-favicon": "^2.2.0",
5656
"stable": "^0.1.5",
5757
"strong-globalize": "^2.6.2",
58-
"strong-remoting": "^3.0.0-alpha.5",
58+
"strong-remoting": "^3.0.0-alpha.6",
5959
"uid2": "0.0.3",
6060
"underscore.string": "^3.0.3"
6161
},

test/relations.integration.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ describe('relations - integration', function() {
656656

657657
describe('hasAndBelongsToMany', function() {
658658
beforeEach(function defineProductAndCategoryModels() {
659+
// Disable "Warning: overriding remoting type product"
660+
this.app.remotes()._typeRegistry._options.warnWhenOverridingType = false;
661+
659662
var product = app.registry.createModel(
660663
'product',
661664
{ id: 'string', name: 'string' }

test/remote-connector.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ describe('RemoteConnector', function() {
1515
beforeEach: function(done) {
1616
var test = this;
1717
remoteApp = loopback();
18-
remoteApp.set('remoting', { errorHandler: { debug: true, log: false }});
18+
remoteApp.set('remoting', {
19+
errorHandler: { debug: true, log: false },
20+
types: { warnWhenOverridingType: false },
21+
});
1922
remoteApp.use(loopback.rest());
2023
remoteApp.listen(0, function() {
2124
test.dataSource = loopback.createDataSource({
@@ -51,6 +54,9 @@ describe('RemoteConnector', function() {
5154
beforeEach(function(done) {
5255
var test = this;
5356
remoteApp = this.remoteApp = loopback();
57+
remoteApp.set('remoting', {
58+
types: { warnWhenOverridingType: false },
59+
});
5460
remoteApp.use(loopback.rest());
5561
var ServerModel = this.ServerModel = loopback.PersistedModel.extend('TestModel');
5662

test/user.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe('User', function() {
7070
app.enableAuth({ dataSource: 'db' });
7171
app.use(loopback.token({ model: AccessToken }));
7272
app.use(loopback.rest());
73-
app.model(User);
7473

7574
User.create(validCredentials, function(err, user) {
7675
if (err) return done(err);

0 commit comments

Comments
 (0)