Function getDiscriminatorModelForClass

  • Build a Model from the given Class and add it as a discriminator onto "from"

    Type Parameters

    Parameters

    • from: mongoose.Model<any, any, any, any, any, any>

      The Model to add the new discriminator model to

    • cl: U

      The Class to make a discriminator model from

    • Optional options: IModelOptions

      Overwrite ModelOptions (Merged with ModelOptions from class)

      Optional

    Returns ReturnModelType<U, QueryHelpers>

    Example

    class Main {
    @prop({ ref: () => BaseDiscriminator })
    public discriminators?: Ref<BaseDiscriminator>;
    }

    class BaseDiscriminator {
    @prop()
    public propertyOnAllDiscriminators?: string;
    }

    class AnotherDiscriminator {
    @prop()
    public someValue?: string;
    }

    const MainModel = getModelForClass(Main);

    const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
    const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
    // add other discriminator models the same way as "AnotherDiscriminatorModel"
  • Build a Model from the given Class and add it as a discriminator onto "from"

    Type Parameters

    Parameters

    • from: mongoose.Model<any, any, any, any, any, any>

      The Model to add the new discriminator model to

    • cl: U

      The Class to make a discriminator model from

    • Optional value: string

      The Identifier to use to differentiate documents (default: cl.name)

      Optional

    Returns ReturnModelType<U, QueryHelpers>

    Example

    class Main {
    @prop({ ref: () => BaseDiscriminator })
    public discriminators?: Ref<BaseDiscriminator>;
    }

    class BaseDiscriminator {
    @prop()
    public propertyOnAllDiscriminators?: string;
    }

    class AnotherDiscriminator {
    @prop()
    public someValue?: string;
    }

    const MainModel = getModelForClass(Main);

    const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
    const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
    // add other discriminator models the same way as "AnotherDiscriminatorModel"
  • Build a Model from the given Class and add it as a discriminator onto "from"

    Type Parameters

    Parameters

    • from: mongoose.Model<any, any, any, any, any, any>

      The Model to add the new discriminator model to

    • cl: U

      The Class to make a discriminator model from

    • Optional value: string

      The Identifier to use to differentiate documents (default: cl.name)

      Optional
    • Optional options: IModelOptions

      Overwrite ModelOptions (Merged with ModelOptions from class)

      Optional

    Returns ReturnModelType<U, QueryHelpers>

    Example

    class Main {
    @prop({ ref: () => BaseDiscriminator })
    public discriminators?: Ref<BaseDiscriminator>;
    }

    class BaseDiscriminator {
    @prop()
    public propertyOnAllDiscriminators?: string;
    }

    class AnotherDiscriminator {
    @prop()
    public someValue?: string;
    }

    const MainModel = getModelForClass(Main);

    const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
    const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
    // add other discriminator models the same way as "AnotherDiscriminatorModel"

Generated using TypeDoc