Fix hasMany / relational methods. Update docs.
This commit is contained in:
parent
8a7086be5c
commit
755b54f697
|
@ -136,12 +136,18 @@ Require a value for `property` to be a specific type of `Number`.
|
||||||
|
|
||||||
#### Model.validatesUniquenessOf(property, options)
|
#### 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'});
|
User.validatesUniquenessOf('email', {message: 'email is not unique'});
|
||||||
|
|
||||||
**Note:** not available for all [connectors](#connectors).
|
**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()
|
#### myModel.isValid()
|
||||||
|
|
||||||
Validate the model instance.
|
Validate the model instance.
|
||||||
|
|
|
@ -116,9 +116,8 @@ loopback.createDataSource = function (name, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluralized = i8n.pluralize(anotherClass.modelName);
|
var pluralized = anotherClass.pluralModelName || i8n.pluralize(anotherClass.modelName);
|
||||||
var methodName = params.as ||
|
var methodName = params.as || i8n.camelize(i8n.pluralize(anotherClass.modelName), true);
|
||||||
i8n.camelize(pluralized, true);
|
|
||||||
var proxyMethodName = 'get' + i8n.titleize(pluralized, true);
|
var proxyMethodName = 'get' + i8n.titleize(pluralized, true);
|
||||||
|
|
||||||
// create a proxy method
|
// create a proxy method
|
||||||
|
@ -127,12 +126,14 @@ loopback.createDataSource = function (name, options) {
|
||||||
// because it is defined inside
|
// because it is defined inside
|
||||||
// a property getter...
|
// a property getter...
|
||||||
|
|
||||||
this[methodName].apply(thisClass, arguments);
|
var f = (this[methodName] || this[pluralized]);
|
||||||
|
f.apply(thisClass, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
fn.shared = true;
|
fn.shared = true;
|
||||||
fn.http = {verb: 'get', path: '/' + methodName};
|
fn.http = {verb: 'get', path: '/' + pluralized};
|
||||||
fn.accepts = {arg: 'where', type: 'object'};
|
fn.accepts = {arg: 'where', type: 'object'};
|
||||||
|
fn.returns = {root: true};
|
||||||
hasMany.apply(this, arguments);
|
hasMany.apply(this, arguments);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ Model.setup = function () {
|
||||||
];
|
];
|
||||||
|
|
||||||
ModelCtor.sharedCtor.returns = {root: true};
|
ModelCtor.sharedCtor.returns = {root: true};
|
||||||
|
|
||||||
return ModelCtor;
|
return ModelCtor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue