waterline
Advanced tools
Comparing version 0.10.12 to 0.10.13
@@ -7,2 +7,3 @@ | ||
var _ = require('lodash'); | ||
var Bluebird = require('bluebird'); | ||
var Model = require('./lib/model'); | ||
@@ -79,16 +80,26 @@ var defaultMethods = require('./lib/defaultMethods'); | ||
* | ||
* @param {Function} callback | ||
* @return callback - (err) | ||
* @param {Function} callback - (err) | ||
* @return {Promise} | ||
*/ | ||
validate: function(cb) { | ||
var self = this; | ||
// Collect current values | ||
var values = this.toObject(); | ||
context.validate( values, function(err) { | ||
if(err) return cb(err); | ||
cb(); | ||
}); | ||
if(cb) { | ||
context.validate(values, function(err) { | ||
if(err) return cb(err); | ||
cb(); | ||
}); | ||
return; | ||
} | ||
else { | ||
return new Bluebird(function (resolve, reject) { | ||
context.validate(values, function(err) { | ||
if(err) return reject(err); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -95,0 +106,0 @@ |
@@ -24,10 +24,15 @@ | ||
var Destroy = module.exports = function(context, proto, cb) { | ||
var values, attributes, primaryKey, deferred, err; | ||
var deferred; | ||
var err; | ||
if(typeof cb !== 'function') { | ||
deferred = defer(); | ||
} | ||
cb = cb || noop; | ||
deferred = defer(); | ||
values = proto.toObject(); | ||
attributes = context.waterline.schema[context.identity].attributes; | ||
primaryKey = this.findPrimaryKey(attributes, values); | ||
var values = proto.toObject(); | ||
var attributes = context.waterline.schema[context.identity].attributes; | ||
var primaryKey = this.findPrimaryKey(attributes, values); | ||
@@ -37,3 +42,7 @@ if(!primaryKey) { | ||
'Try setting an attribute as a primary key or include an ID property.'); | ||
deferred.reject(err); | ||
if(deferred) { | ||
deferred.reject(err); | ||
} | ||
return cb(err); | ||
@@ -45,3 +54,7 @@ } | ||
'Primary Key must have a value, it can\'t be an optional value.'); | ||
deferred.reject(err); | ||
if(deferred) { | ||
deferred.reject(err); | ||
} | ||
return cb(err); | ||
@@ -57,10 +70,20 @@ } | ||
if (err) { | ||
deferred.reject(err); | ||
if(deferred) { | ||
deferred.reject(err); | ||
} | ||
return cb(err); | ||
} | ||
deferred.resolve(status); | ||
if(deferred) { | ||
deferred.resolve(status); | ||
} | ||
cb.apply(this, arguments); | ||
}); | ||
return deferred.promise; | ||
if(deferred) { | ||
return deferred.promise; | ||
} | ||
}; | ||
@@ -67,0 +90,0 @@ |
@@ -25,3 +25,9 @@ var _ = require('lodash'); | ||
module.exports = function(context, proto, cb) { | ||
var deferred = defer(); | ||
var deferred; | ||
if(typeof cb !== 'function') { | ||
deferred = defer(); | ||
} | ||
cb = cb || noop; | ||
@@ -137,5 +143,9 @@ | ||
}, function(err, results) { | ||
}, | ||
function(err, results) { | ||
if(err) { | ||
deferred.reject(err); | ||
if(deferred) { | ||
deferred.reject(err); | ||
} | ||
return cb(err); | ||
@@ -156,3 +166,5 @@ } | ||
if(failedTransactions.length > 0) { | ||
deferred.reject(failedTransactions); | ||
if(deferred) { | ||
deferred.reject(failedTransactions); | ||
} | ||
return cb(failedTransactions); | ||
@@ -166,3 +178,5 @@ } | ||
var error = new Error('Error updating a record.'); | ||
deferred.reject(error); | ||
if(deferred) { | ||
deferred.reject(error); | ||
} | ||
return cb(error); | ||
@@ -183,8 +197,13 @@ } | ||
query.exec(function(err, data) { | ||
if(err) | ||
{ | ||
deferred.reject(err); | ||
if(err) { | ||
if(deferred) { | ||
deferred.reject(err); | ||
} | ||
return cb(err); | ||
} | ||
deferred.resolve(data); | ||
if(deferred) { | ||
deferred.resolve(data); | ||
} | ||
cb(null, data); | ||
@@ -194,3 +213,5 @@ }); | ||
return deferred.promise; | ||
if(deferred) { | ||
return deferred.promise; | ||
} | ||
}; |
@@ -46,3 +46,6 @@ /** | ||
var errStr = _validateValues(valuesList); | ||
// Remove all undefined values | ||
valuesList = _.remove(valuesList, undefined); | ||
var errStr = _validateValues(_.cloneDeep(valuesList)); | ||
if(errStr) return usageError(errStr, usage, cb); | ||
@@ -106,3 +109,8 @@ | ||
// pass the array to the adapter's findOrCreateEach method | ||
async.each(valuesList, function(item, next) { _validate.call(self, item, next); }, function(err) { | ||
var validateItem = function(item, next) { | ||
_validate.call(self, item, next); | ||
} | ||
async.each(valuesList, validateItem, function(err) { | ||
if(err) return cb(err); | ||
@@ -109,0 +117,0 @@ |
@@ -33,2 +33,9 @@ /** | ||
values = values || {}; | ||
// Remove all undefined values | ||
if(_.isArray(values)) { | ||
values = _.remove(values, undefined); | ||
} | ||
// Return Deferred or pass to adapter | ||
@@ -39,2 +46,3 @@ if(typeof cb !== 'function') { | ||
// Handle Array of values | ||
@@ -41,0 +49,0 @@ if(Array.isArray(values)) { |
@@ -309,6 +309,4 @@ | ||
var self = this, | ||
connections = {}, | ||
collection, | ||
collectionName; | ||
var self = this; | ||
var connections = {}; | ||
@@ -329,2 +327,8 @@ // Default structure for connection objects | ||
// Grab the parent collection | ||
var collection = self.context.waterline.collections[join.parent]; | ||
// Find the connection object in the registry | ||
var connectionName = collection.adapterDictionary['find']; | ||
// If this join is a junctionTable, find the parent operation and add it to that connections | ||
@@ -355,5 +359,5 @@ // children instead of creating a new operation on another connection. This allows cross-connection | ||
function updateRegistry(collName) { | ||
collection = self.context.waterline.collections[collName]; | ||
connectionName = collection.adapterDictionary['find']; | ||
connections[connectionName] = connections[connectionName] || _.clone(defaultConnection); | ||
var collection = self.context.waterline.collections[collName]; | ||
var connectionName = collection.adapterDictionary['find']; | ||
connections[connectionName] = connections[connectionName] || _.cloneDeep(defaultConnection); | ||
@@ -360,0 +364,0 @@ // Update the registry with the join values |
{ | ||
"name": "waterline", | ||
"description": "An ORM for Node.js and the Sails framework", | ||
"version": "0.10.12", | ||
"version": "0.10.13", | ||
"homepage": "http://github.com/balderdashy/waterline", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
330651
8843