diff --git a/src/services/populate.js b/src/services/populate.js index bce070b6..af672696 100755 --- a/src/services/populate.js +++ b/src/services/populate.js @@ -206,7 +206,7 @@ function populateAddChild (options, hook, parentItem, childSchema, depth) { result = result[0]; } - return childSchema.include + return (childSchema.include && result) ? populateItemArray(options, hook, result, childSchema.include, depth) : result; }) .then(items => ({ nameAs, items })); diff --git a/test/helpers/get-init-db.js b/test/helpers/get-init-db.js index 64bd69d9..5f1e09ee 100755 --- a/test/helpers/get-init-db.js +++ b/test/helpers/get-init-db.js @@ -56,7 +56,15 @@ module.exports = function (name) { author: '167asdf3689348sdad7312131s', readers: ['as61389dadhga62343hads6712', '167asdf3689348sdad7312131s'], createdAt: 1480793101559 - } + }, + '4': { + id: 4, + title: 'Post 4', + content: 'Lorem ipsum dolor sit amet 5', + author: '167asdf3689348sdad7312131s', + readers: [], + createdAt: 1480793101559 + } }; const recommendation = {