From 563b0518285e263e91f126a25bf643249fcc53e2 Mon Sep 17 00:00:00 2001 From: Michael Ermer Date: Mon, 24 Jul 2017 23:51:10 +0200 Subject: [PATCH] move $populate parameter to params --- lib/populate/index.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/populate/index.js b/lib/populate/index.js index d604fe9..b31b511 100644 --- a/lib/populate/index.js +++ b/lib/populate/index.js @@ -1,14 +1,4 @@ 'use strict' -module.exports.compatibility = function(options) { - return function(hook) { - // move query to params - if (hook && hook.params && hook.params.query && hook.params.query.$populate) { - hook.params.$populate = hook.params.query.$populate; - delete hook.params.query.$populate; - } - return hook; - }; -}; module.exports = function populate (options) { /** @@ -45,6 +35,9 @@ module.exports = function populate (options) { * set query.$populate to false to block all populates **/ let skip = {}; + if (hook.params.$populate==='false' || hook.params.$populate==='0' || hook.params.$populate===0) { + hook.params.$populate = false; + } if (hook.params.$populate || hook.params.$populate===false) { if (hook.params.$populate.constructor === Object) { Object.keys(hook.params.$populate).map(function(key) { @@ -102,3 +95,14 @@ module.exports = function populate (options) { return hook; }; }; + +module.exports.compatibility = function(options) { + return function(hook) { + // move query to params + if (hook && hook.params && hook.params.query && hook.params.query.$populate) { + hook.params.$populate = hook.params.query.$populate; + delete hook.params.query.$populate; + } + return hook; + }; +};