all files / keystone/lib/core/ populateRelated.js

22.22% Statements 2/9
0% Branches 0/6
0% Functions 0/2
22.22% Lines 2/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                                            
var async = require('async');
 
/**
 * Populates relationships on a document or array of documents
 *
 * WARNING: This is currently highly inefficient and should only be used in development, or for
 * small data sets. There are lots of things that can be done to improve performance... later.
 *
 * @api public
 */
 
module.exports = function populateRelated (docs, relationships, callback) {
	if (Array.isArray(docs)) {
		async.each(docs, function (doc, done) {
			doc.populateRelated(relationships, done);
		}, callback);
	} else if (docs && docs.populateRelated) {
		docs.populateRelated(relationships, callback);
	} else {
		callback();
	}
	return this;
};