diff --git a/README.md b/README.md index 7d210ab6..ee2bf258 100644 --- a/README.md +++ b/README.md @@ -136,12 +136,18 @@ Require a value for `property` to be a specific type of `Number`. #### Model.validatesUniquenessOf(property, options) -Ensure the value for `property` is unique. +Ensure the value for `property` is unique in the collection of models. User.validatesUniquenessOf('email', {message: 'email is not unique'}); **Note:** not available for all [connectors](#connectors). +Currently supported in these connectors: + + - [In Memory](#memory-connector) + - [Oracle](http://github.com/strongloop/loopback-connector-oracle) + - [MongoDB](http://github.com/strongloop/loopback-connector-mongodb) + #### myModel.isValid() Validate the model instance. diff --git a/lib/loopback.js b/lib/loopback.js index a5466db0..639eeddf 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -116,9 +116,8 @@ loopback.createDataSource = function (name, options) { } } - var pluralized = i8n.pluralize(anotherClass.modelName); - var methodName = params.as || - i8n.camelize(pluralized, true); + var pluralized = anotherClass.pluralModelName || i8n.pluralize(anotherClass.modelName); + var methodName = params.as || i8n.camelize(i8n.pluralize(anotherClass.modelName), true); var proxyMethodName = 'get' + i8n.titleize(pluralized, true); // create a proxy method @@ -127,12 +126,14 @@ loopback.createDataSource = function (name, options) { // because it is defined inside // a property getter... - this[methodName].apply(thisClass, arguments); + var f = (this[methodName] || this[pluralized]); + f.apply(thisClass, arguments); }; fn.shared = true; - fn.http = {verb: 'get', path: '/' + methodName}; + fn.http = {verb: 'get', path: '/' + pluralized}; fn.accepts = {arg: 'where', type: 'object'}; + fn.returns = {root: true}; hasMany.apply(this, arguments); }; } diff --git a/lib/models/model.js b/lib/models/model.js index 05e6034e..0f38c902 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -108,7 +108,7 @@ Model.setup = function () { ]; ModelCtor.sharedCtor.returns = {root: true}; - + return ModelCtor; }