keystone
Version:
Web Application Framework and Admin GUI / Content Management System built on Express.js and Mongoose
24 lines (21 loc) • 659 B
JavaScript
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;
};