Skip to content

Commit

Permalink
Merge pull request Automattic#12737 from Automattic/vkarpov15/Automat…
Browse files Browse the repository at this point in the history
…ticgh-12654

fix(schema): copy indexes when calling `add()` with schema instance
  • Loading branch information
rdeavila94 committed Mar 6, 2023
1 parent e76c41c commit d0e149b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/helpers/schema/merge.js
Expand Up @@ -23,5 +23,6 @@ module.exports = function merge(s1, s2, skipConflictingPaths) {
s1.virtuals[virtual] = s2.virtuals[virtual].clone();
}

s1._indexes = s1._indexes.concat(s2._indexes || []);
s1.s.hooks.merge(s2.s.hooks, false);
};
10 changes: 10 additions & 0 deletions test/schema.test.js
Expand Up @@ -2401,6 +2401,16 @@ describe('schema', function() {
assert.equal(TurboManSchema.path('year').instance, 'Number');
});

it('copies indexes when calling add() with schema instance (gh-12654)', function() {
const ToySchema = Schema({ name: String });
ToySchema.index({ name: 1 });

const TurboManSchema = Schema();
TurboManSchema.add(ToySchema);

assert.deepStrictEqual(TurboManSchema.indexes(), [[{ name: 1 }, { background: true }]]);
});

describe('gh-8849', function() {
it('treats `select: undefined` as not specifying `select` option', function() {
const userSchema = new Schema({ name: { type: String, select: undefined } });
Expand Down

0 comments on commit d0e149b

Please sign in to comment.