small sentence fixes + added usage examples in belongsTo comments

This commit is contained in:
Sébastien Drouyer 2012-11-03 01:39:35 +01:00
parent 89b8329764
commit fe8ed86301
1 changed files with 19 additions and 2 deletions

View File

@ -709,6 +709,23 @@ AbstractClass.hasMany = function hasMany(anotherClass, params) {
*
* @param {Class} anotherClass - class to belong
* @param {Object} params - configuration {as: 'propertyName', foreignKey: 'keyName'}
*
* {Usage examples}
* Suppose model Post have a {belongsTo} relationship with User (the author of the post). You could declare it this way:
* Post.belongsTo(User, {as: 'author', foreignKey: 'userId'});
*
* When a post is loaded, you can load the related author with:
* post.author(function(err, user) {
* // the user variable is your user object
* });
*
* The related object is cached, so if later you try to get again the author, no additional request will be made.
* But there is an optional boolean parameter in first position that set whether or not you want to reload the cache:
* post.author(true, function(err, user) {
* // The user is reloaded, even if it was already cached.
* });
*
* This optional parameter default value is false, so the related object will be loaded from cache if available.
*/
AbstractClass.belongsTo = function (anotherClass, params) {
var methodName = params.as;
@ -734,7 +751,7 @@ AbstractClass.belongsTo = function (anotherClass, params) {
p = refresh;
refresh = false;
} else if (arguments.length > 2) {
throw new Error('Method only can\'t be only called with more than two arguments');
throw new Error('Method can\'t be called with more than two arguments');
}
var self = this;
var cachedValue;
@ -811,7 +828,7 @@ function defineScope(cls, targetClass, name, params, methods) {
saveOnCache = false;
}
} else {
throw new Error('Method only can be only called with one or two arguments');
throw new Error('Method can be only called with one or two arguments');
}
if (!this.__cachedRelations || (typeof this.__cachedRelations[name] == 'undefined') || actualRefresh) {