Skip to content

Commit

Permalink
Merge pull request #1225 from Dukezo/master
Browse files Browse the repository at this point in the history
feat: add option to specify a discriminator value
  • Loading branch information
kamilmysliwiec committed May 20, 2022
2 parents 84ad659 + a338213 commit 72ce783
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/interfaces/model-definition.interface.ts
Expand Up @@ -3,6 +3,7 @@ import { Schema } from 'mongoose';
export type DiscriminatorOptions = {
name: string;
schema: Schema;
value?: string;
};

export type ModelDefinition = {
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoose.providers.ts
Expand Up @@ -13,7 +13,7 @@ export function createMongooseProviders(
...(option.discriminators || []).map((d) => ({
provide: getModelToken(d.name, connectionName),
useFactory: (model: Model<Document>) =>
model.discriminator(d.name, d.schema),
model.discriminator(d.name, d.schema, d.value),
inject: [getModelToken(option.name, connectionName)],
})),
{
Expand Down Expand Up @@ -56,7 +56,7 @@ export function createMongooseAsyncProviders(
...(option.discriminators || []).map((d) => ({
provide: getModelToken(d.name, connectionName),
useFactory: (model: Model<Document>) =>
model.discriminator(d.name, d.schema),
model.discriminator(d.name, d.schema, d.value),
inject: [getModelToken(option.name, connectionName)],
})),
];
Expand Down

0 comments on commit 72ce783

Please sign in to comment.