Skip to content

Commit

Permalink
Merge pull request #15138 from IchirokuXVI/fix-ref-manual-populate
Browse files Browse the repository at this point in the history
Fix document not applying manual populate when using a function in schema.options.ref
  • Loading branch information
vkarpov15 authored Jan 4, 2025
2 parents 56909d0 + 305997a commit 5dcca7e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const documentIsModified = require('./helpers/symbols').documentIsModified;
const documentModifiedPaths = require('./helpers/symbols').documentModifiedPaths;
const documentSchemaSymbol = require('./helpers/symbols').documentSchemaSymbol;
const getSymbol = require('./helpers/symbols').getSymbol;
const modelSymbol = require('./helpers/symbols').modelSymbol;
const populateModelSymbol = require('./helpers/symbols').populateModelSymbol;
const scopeSymbol = require('./helpers/symbols').scopeSymbol;
const schemaMixedSymbol = require('./schema/symbols').schemaMixedSymbol;
Expand Down Expand Up @@ -1386,7 +1387,9 @@ Document.prototype.$set = function $set(path, val, type, options) {
const model = val.constructor;

// Check ref
const ref = schema.options.ref;
const refOpt = typeof schema.options.ref === 'function' && !schema.options.ref[modelSymbol] ? schema.options.ref.call(this, this) : schema.options.ref;

const ref = refOpt?.modelName || refOpt;
if (ref != null && (ref === model.modelName || ref === model.baseModelName)) {
return true;
}
Expand Down

0 comments on commit 5dcca7e

Please sign in to comment.