Skip to content

Commit 723ab31

Browse files
author
Ajay Prajapati
committed
allow empty array in createAll method
1 parent 337391a commit 723ab31

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/dao.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,18 @@ DataAccessObject.createAll = function(dataArray, options, cb) {
512512
options = options || {};
513513
cb = cb || utils.createPromiseCallback();
514514

515-
assert(typeof dataArray === 'object' && dataArray.length,
516-
'The data argument must be an array with length > 0');
515+
assert(typeof dataArray === 'object' && Array.isArray(dataArray),
516+
'The data argument must be an array');
517517
assert(typeof options === 'object', 'The options argument must be an object');
518518
assert(typeof cb === 'function', 'The cb argument must be a function');
519519

520+
if (dataArray.length === 0) {
521+
process.nextTick(function() {
522+
cb(null, []);
523+
});
524+
return cb.promise;
525+
}
526+
520527
const validationPromises = [];
521528
for (let index = 0; index < dataArray.length; index++) {
522529
const data = dataArray[index];

0 commit comments

Comments
 (0)