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`.
This commit is contained in:
Miroslav Bajtoš 2014-01-21 16:50:18 +01:00
parent 54bff35fef
commit 8bb8861ba1
2 changed files with 5 additions and 5 deletions

View File

@ -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;
}
});

View File

@ -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 {