From f43a984e31049bc2c8b65df617e0779d4c6b3178 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 30 Oct 2017 12:36:19 -0700 Subject: [PATCH] fix(schema): make clone() copy query helpers correctly Fix #5752 --- lib/schema.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index 52ec2bae076..48acab99cb2 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -298,11 +298,13 @@ Schema.prototype.tree; Schema.prototype.clone = function() { var s = new Schema(this.paths, this.options); // Clone the call queue + var cloneOpts = { retainKeyOrder: true }; s.callQueue = this.callQueue.map(function(f) { return f; }); - s.methods = utils.clone(this.methods); - s.statics = utils.clone(this.statics); + s.methods = utils.clone(this.methods, cloneOpts); + s.statics = utils.clone(this.statics, cloneOpts); + s.query = utils.clone(this.query, cloneOpts); s.plugins = Array.prototype.slice.call(this.plugins); - s._indexes = utils.clone(this._indexes); + s._indexes = utils.clone(this._indexes, cloneOpts); s.s.hooks = this.s.hooks.clone(); return s; };