From 2c2b5a3eec3eac9765872c8967cfb4b2a6fe8968 Mon Sep 17 00:00:00 2001 From: John Szwaronek Date: Sat, 20 May 2017 10:57:04 -0400 Subject: [PATCH] Fixed populate issue with recursive include --- src/services/populate.js | 2 +- test/helpers/get-init-db.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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 = {