Permalink
Browse files

added the connection as an argument in the method validation. If the

return of the validation is not a string object itself is returned.
  • Loading branch information...
1 parent 233008d commit 8b09c6b427e58552aa2356fd19177c6be179d801 @peruzzo peruzzo committed Sep 13, 2013
Showing with 22 additions and 6 deletions.
  1. +22 −6 lib/connection.js
View
@@ -58,24 +58,40 @@ var Connection = Class.extend({
var self = this;
if (obj.validate && typeof(obj.validate) === 'function') {
- return obj.validate(function(success, message) {
+ var args = [];
+ if (obj.validate.length === 2) {
+ args.push(self);
+ }
+
+ args.push(function(success, message) {
if (success) {
return doModelValidation();
}
- return callback(new Error("Validation failed: " + message));
+ return callback(typeof(message) === 'string' ? new Error("Validation failed: " + message) : message);
});
+
+ return obj.validate.apply(null, args);
+
} else {
return doModelValidation();
}
function doModelValidation() {
- if (obj._getModel().validate) {
- return obj._getModel().validate(obj, function(success, message) {
+ if (obj._getModel().validate) {
+ var args = [obj];
+ if (obj._getModel().validate.length === 3) {
+ args.push(self);
+ }
+
+ args.push(function(success, message) {
if (success) {
return doSave();
}
- return callback(new Error("Validation failed: " + message));
- });
+ return callback(typeof(message) === 'string' ? new Error("Validation failed: " + message) : message);
+ });
+
+ return obj._getModel().validate.apply(null, args);
+
} else {
return doSave();
}

0 comments on commit 8b09c6b

Please sign in to comment.