Skip to content

Commit 7a0b15f

Browse files
committed
style: fix lint
1 parent 7677cf3 commit 7a0b15f

File tree

2 files changed

+85
-87
lines changed

2 files changed

+85
-87
lines changed

lib/model.js

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,101 +3568,21 @@ function getModelsMapForPopulate(model, docs, options) {
35683568
}
35693569

35703570
if (Array.isArray(schema)) {
3571-
for (var i = 0; i < schema.length; ++i) {
3572-
var _modelNames = _getModelNames(schema[i]);
3571+
for (var j = 0; j < schema.length; ++j) {
3572+
var _modelNames = _getModelNames(doc, schema[j]);
35733573
if (!_modelNames) {
35743574
continue;
35753575
}
35763576
modelNames = (modelNames || []).concat(_modelNames);
35773577
}
35783578
} else {
3579-
modelNames = _getModelNames(schema);
3579+
modelNames = _getModelNames(doc, schema);
35803580
if (!modelNames) {
35813581
continue;
35823582
}
35833583
}
35843584

3585-
function _getModelNames(schema) {
3586-
var modelNames;
3587-
3588-
if (schema && schema.caster) {
3589-
schema = schema.caster;
3590-
}
3591-
3592-
if (!schema && model.discriminators) {
3593-
discriminatorKey = model.schema.discriminatorMapping.key;
3594-
}
3595-
3596-
refPath = schema && schema.options && schema.options.refPath;
3597-
3598-
if (refPath) {
3599-
modelNames = utils.getValue(refPath, doc);
3600-
isRefPathArray = Array.isArray(modelNames);
3601-
} else {
3602-
if (!modelNameFromQuery) {
3603-
var modelForCurrentDoc = model;
3604-
var schemaForCurrentDoc;
3605-
3606-
if (!schema && discriminatorKey) {
3607-
modelForFindSchema = utils.getValue(discriminatorKey, doc);
3608-
3609-
if (modelForFindSchema) {
3610-
try {
3611-
modelForCurrentDoc = model.db.model(modelForFindSchema);
3612-
} catch (error) {
3613-
return error;
3614-
}
3615-
3616-
schemaForCurrentDoc = modelForCurrentDoc.schema._getSchema(options.path);
3617-
3618-
if (schemaForCurrentDoc && schemaForCurrentDoc.caster) {
3619-
schemaForCurrentDoc = schemaForCurrentDoc.caster;
3620-
}
3621-
}
3622-
} else {
3623-
schemaForCurrentDoc = schema;
3624-
}
3625-
var virtual = modelForCurrentDoc.schema._getVirtual(options.path);
3626-
3627-
var ref;
3628-
if ((ref = get(schemaForCurrentDoc, 'options.ref')) != null) {
3629-
modelNames = [ref];
3630-
} else if ((ref = get(virtual, 'options.ref')) != null) {
3631-
if (typeof ref === 'function') {
3632-
ref = ref.call(doc, doc);
3633-
}
3634-
3635-
// When referencing nested arrays, the ref should be an Array
3636-
// of modelNames.
3637-
if (Array.isArray(ref)) {
3638-
modelNames = ref;
3639-
} else {
3640-
modelNames = [ref];
3641-
}
3642-
3643-
isVirtual = true;
3644-
} else {
3645-
// We may have a discriminator, in which case we don't want to
3646-
// populate using the base model by default
3647-
modelNames = discriminatorKey ? null : [model.modelName];
3648-
}
3649-
} else {
3650-
modelNames = [modelNameFromQuery]; // query options
3651-
}
3652-
}
3653-
3654-
if (!modelNames) {
3655-
return;
3656-
}
3657-
3658-
if (!Array.isArray(modelNames)) {
3659-
modelNames = [modelNames];
3660-
}
3661-
3662-
return modelNames;
3663-
}
3664-
3665-
virtual = model.schema._getVirtual(options.path);
3585+
var virtual = model.schema._getVirtual(options.path);
36663586
var localField;
36673587
if (virtual && virtual.options) {
36683588
var virtualPrefix = virtual.$nestedSchemaPath ?
@@ -3752,6 +3672,86 @@ function getModelsMapForPopulate(model, docs, options) {
37523672
}
37533673
}
37543674

3675+
function _getModelNames(doc, schema) {
3676+
var modelNames;
3677+
3678+
if (schema && schema.caster) {
3679+
schema = schema.caster;
3680+
}
3681+
3682+
if (!schema && model.discriminators) {
3683+
discriminatorKey = model.schema.discriminatorMapping.key;
3684+
}
3685+
3686+
refPath = schema && schema.options && schema.options.refPath;
3687+
3688+
if (refPath) {
3689+
modelNames = utils.getValue(refPath, doc);
3690+
isRefPathArray = Array.isArray(modelNames);
3691+
} else {
3692+
if (!modelNameFromQuery) {
3693+
var modelForCurrentDoc = model;
3694+
var schemaForCurrentDoc;
3695+
3696+
if (!schema && discriminatorKey) {
3697+
modelForFindSchema = utils.getValue(discriminatorKey, doc);
3698+
3699+
if (modelForFindSchema) {
3700+
try {
3701+
modelForCurrentDoc = model.db.model(modelForFindSchema);
3702+
} catch (error) {
3703+
return error;
3704+
}
3705+
3706+
schemaForCurrentDoc = modelForCurrentDoc.schema._getSchema(options.path);
3707+
3708+
if (schemaForCurrentDoc && schemaForCurrentDoc.caster) {
3709+
schemaForCurrentDoc = schemaForCurrentDoc.caster;
3710+
}
3711+
}
3712+
} else {
3713+
schemaForCurrentDoc = schema;
3714+
}
3715+
var virtual = modelForCurrentDoc.schema._getVirtual(options.path);
3716+
3717+
var ref;
3718+
if ((ref = get(schemaForCurrentDoc, 'options.ref')) != null) {
3719+
modelNames = [ref];
3720+
} else if ((ref = get(virtual, 'options.ref')) != null) {
3721+
if (typeof ref === 'function') {
3722+
ref = ref.call(doc, doc);
3723+
}
3724+
3725+
// When referencing nested arrays, the ref should be an Array
3726+
// of modelNames.
3727+
if (Array.isArray(ref)) {
3728+
modelNames = ref;
3729+
} else {
3730+
modelNames = [ref];
3731+
}
3732+
3733+
isVirtual = true;
3734+
} else {
3735+
// We may have a discriminator, in which case we don't want to
3736+
// populate using the base model by default
3737+
modelNames = discriminatorKey ? null : [model.modelName];
3738+
}
3739+
} else {
3740+
modelNames = [modelNameFromQuery]; // query options
3741+
}
3742+
}
3743+
3744+
if (!modelNames) {
3745+
return;
3746+
}
3747+
3748+
if (!Array.isArray(modelNames)) {
3749+
modelNames = [modelNames];
3750+
}
3751+
3752+
return modelNames;
3753+
}
3754+
37553755
return map;
37563756
}
37573757

lib/services/populate/getSchemaTypes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66

77
var Mixed = require('../../schema/mixed');
8-
var get = require('lodash.get');
98
var mpath = require('mpath');
10-
var utils = require('../../utils');
119

1210
/*!
1311
* ignore
@@ -112,4 +110,4 @@ module.exports = function getSchemaTypes(schema, doc, path) {
112110
}
113111
}
114112
return search(parts, schema);
115-
}
113+
};

0 commit comments

Comments
 (0)