Skip to content

Commit

Permalink
refactor(typegoose::getModelForClass): rename value to be more intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed May 28, 2022
1 parent 1cb946f commit b504314
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/typegoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ export function getModelForClass<U extends AnyParamConstructor<any>, QueryHelper
assertionIsClass(cl);
options = typeof options === 'object' ? options : {};

const roptions: IModelOptions = mergeMetadata(DecoratorKeys.ModelOptions, options, cl);
const mergedOptions: IModelOptions = mergeMetadata(DecoratorKeys.ModelOptions, options, cl);
const name = getName(cl, options);

if (models.has(name)) {
return models.get(name) as ReturnModelType<U, QueryHelpers>;
}

const model =
roptions?.existingConnection?.model.bind(roptions.existingConnection) ??
roptions?.existingMongoose?.model.bind(roptions.existingMongoose) ??
mergedOptions?.existingConnection?.model.bind(mergedOptions.existingConnection) ??
mergedOptions?.existingMongoose?.model.bind(mergedOptions.existingMongoose) ??
mongoose.model.bind(mongoose);

const compiledmodel: mongoose.Model<any> = model(name, buildSchema(cl, roptions.schemaOptions, options));
const compiledmodel: mongoose.Model<any> = model(name, buildSchema(cl, mergedOptions.schemaOptions, options));
const refetchedOptions = (Reflect.getMetadata(DecoratorKeys.ModelOptions, cl) as IModelOptions) ?? {};

if (refetchedOptions?.options?.runSyncIndexes) {
Expand All @@ -86,8 +86,8 @@ export function getModelForClass<U extends AnyParamConstructor<any>, QueryHelper
}

return addModelToTypegoose<U, QueryHelpers>(compiledmodel, cl, {
existingMongoose: roptions?.existingMongoose,
existingConnection: roptions?.existingConnection,
existingMongoose: mergedOptions?.existingMongoose,
existingConnection: mergedOptions?.existingConnection,
});
}

Expand Down

0 comments on commit b504314

Please sign in to comment.