getDiscriminatorModelForClass
Overload 1
Typings:
function getDiscriminatorModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(
  from: mongoose.Model<any, any>,
  cl: U,
  options?: IModelOptions
): ReturnModelType<U, QueryHelpers>;
Parameters:
| Name | Type | Description | 
|---|---|---|
| fromRequired | mongoose.Model | The Model to register a discriminator on | 
| clRequired | U | The Class to build into a Model | 
| options | IModelOptions | Overwrite some Model options, only property schemaOptionsis merged with the existing options | 
Overload 2
Typings:
function getDiscriminatorModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(
  from: mongoose.Model<any, any>,
  cl: U,
  value?: string
): ReturnModelType<U, QueryHelpers>;
Parameters:
| Name | Type | Description | 
|---|---|---|
| fromRequired | mongoose.Model | The Model to register a discriminator on | 
| clRequired | U | The Class to build into a Model | 
| value | IModelOptions | Overwrite the discrimiantor value to register by | 
Overload 3
Typings:
function getDiscriminatorModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(
  from: mongoose.Model<any, any>,
  cl: U,
  value?: string,
  options?: IModelOptions
): ReturnModelType<U, QueryHelpers>;
Parameters:
| Name | Type | Description | 
|---|---|---|
| fromRequired | mongoose.Model | The Model to register a discriminator on | 
| clRequired | U | The Class to build into a Model | 
| value | IModelOptions | Overwrite the discrimiantor value to register by | 
| options | IModelOptions | Overwrite some Model options, only property schemaOptionsis merged with the existing options | 
Description
getDiscriminatorModelForClass is used to compile a given Class (cl) into a Model and register it as a discriminator on a given Model (from).
Option value is to overwrite the key the class is registered on as a discriminator, by default it is the generated model name, but can be overwritten with any string, recommended is to use a string-enum to keep track of names.
note
Note that existingConnection and existingMongoose will not be used and instead will be registered on the from model's settings.
See Warning W002.
Example
// The Base Class
class Event {
  @prop({ required: true })
  public name!: string;
}
// A Discriminator Class Variant
class ClickEvent extends Event {
  @prop({ required: true, default: 0 })
  public timesClicked!: number;
}
const EventModel = getModelForClass(Event);
const ClickEventModel = getDiscriminatorModelForClass(EventModel, ClickEvent);