Skip to content

Commit

Permalink
fix: propagate lean options to child schemas
Browse files Browse the repository at this point in the history
Fix #5914
  • Loading branch information
vkarpov15 committed Dec 20, 2017
1 parent 4e64596 commit ccec46f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/queryhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ exports.preparePopulationOptions = function preparePopulationOptions(query, opti
var pop = utils.object.vals(query.options.populate);

// lean options should trickle through all queries
if (options.lean) pop.forEach(makeLean);
if (options.lean) {
pop.forEach(makeLean(options.lean));
}

return pop;
};
Expand All @@ -37,7 +39,9 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
var pop = utils.object.vals(query._mongooseOptions.populate);

// lean options should trickle through all queries
if (options.lean) pop.forEach(makeLean);
if (options.lean) {
pop.forEach(makeLean(options.lean));
}

return pop;
};
Expand Down Expand Up @@ -207,7 +211,9 @@ exports.applyPaths = function applyPaths(fields, schema) {
* @param {Object} option
*/

function makeLean(option) {
option.options || (option.options = {});
option.options.lean = true;
function makeLean(val) {
return function(option) {
option.options || (option.options = {});
option.options.lean = val;
};
}

0 comments on commit ccec46f

Please sign in to comment.