From 8bb8861ba15ce2df98c62ff6c73c9f1c579641e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 21 Jan 2014 16:50:18 +0100 Subject: [PATCH] Register exported models using singular names Remove the inconsistency between model names used by LoopBack app and datasource-juggler (modelName, e.g. User) and the name used by strong-remoting (pluralModelName, e.g. Users). This way the class name in the strong-remoting metadata can be used by client-code generators. Before this change, the generators would produce method names like `Users.login`. --- lib/application.js | 6 +++--- lib/models/model.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/application.js b/lib/application.js index 746a5e4f..909d4414 100644 --- a/lib/application.js +++ b/lib/application.js @@ -97,8 +97,8 @@ app.disuse = function (route) { app.model = function (Model, config) { if(arguments.length === 1) { assert(typeof Model === 'function', 'app.model(Model) => Model must be a function / constructor'); - assert(Model.pluralModelName, 'Model must have a "pluralModelName" property'); - this.remotes().exports[Model.pluralModelName] = Model; + assert(Model.modelName, 'Model must have a "modelName" property'); + this.remotes().exports[Model.modelName] = Model; this.models().push(Model); Model.shared = true; Model.app = this; @@ -203,7 +203,7 @@ app.remoteObjects = function () { models.forEach(function (ModelCtor) { // only add shared models if(ModelCtor.shared && typeof ModelCtor.sharedCtor === 'function') { - result[ModelCtor.pluralModelName] = ModelCtor; + result[ModelCtor.modelName] = ModelCtor; } }); diff --git a/lib/models/model.js b/lib/models/model.js index ce2bb5f9..fa350aac 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -69,7 +69,7 @@ Model.setup = function () { var self = this; if(this.app) { var remotes = this.app.remotes(); - remotes.before(self.pluralModelName + '.' + name, function (ctx, next) { + remotes.before(self.modelName + '.' + name, function (ctx, next) { fn(ctx, ctx.result, next); }); } else { @@ -85,7 +85,7 @@ Model.setup = function () { var self = this; if(this.app) { var remotes = this.app.remotes(); - remotes.after(self.pluralModelName + '.' + name, function (ctx, next) { + remotes.after(self.modelName + '.' + name, function (ctx, next) { fn(ctx, ctx.result, next); }); } else {