Fix hasMany / relational methods. Update docs.

This commit is contained in:
Ritchie 2013-07-25 15:27:18 -07:00
parent 8a7086be5c
commit 755b54f697
3 changed files with 14 additions and 7 deletions

View File

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

View File

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

View File

@ -108,7 +108,7 @@ Model.setup = function () {
];
ModelCtor.sharedCtor.returns = {root: true};
return ModelCtor;
}