Documentation
    Preparing search index...

    This is a temporary class used to progressively migrate the Model class to TypeScript by slowly moving its functions here. Always use Model instead.

    Hierarchy (View Summary)

    Index
    addHook: LegacyAddAnyHookFunction<ModelHooks<Model<any, any>, any>>
    afterAssociate: LegacyAddHookFunction<
        (
            data: AfterAssociateEventData,
            options: AssociationOptions<any>,
        ) => AsyncHookReturn,
    >
    afterBulkCreate: LegacyAddHookFunction<
        (
            instances: readonly Model<any, any>[],
            options: BulkCreateOptions<any>,
        ) => AsyncHookReturn,
    >
    afterBulkDestroy: LegacyAddHookFunction<
        (options: DestroyOptions<any>) => AsyncHookReturn,
    >
    afterBulkRestore: LegacyAddHookFunction<
        (options: RestoreOptions<any>) => AsyncHookReturn,
    >
    afterBulkUpdate: LegacyAddHookFunction<
        (options: UpdateOptions<any>) => AsyncHookReturn,
    >
    afterCreate: LegacyAddHookFunction<
        (
            attributes: Model<any, any>,
            options: CreateOptions<any>,
        ) => AsyncHookReturn,
    >
    afterDestroy: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: InstanceDestroyOptions,
        ) => AsyncHookReturn,
    >
    afterFind: LegacyAddHookFunction<
        (
            instancesOrInstance:
                | Model<any, any>
                | readonly Model<any, any>[]
                | null,
            options: FindOptions<any>,
        ) => AsyncHookReturn,
    >
    afterRestore: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: InstanceRestoreOptions,
        ) => AsyncHookReturn,
    >
    afterSave: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: CreateOptions<any> | InstanceUpdateOptions<any>,
        ) => AsyncHookReturn,
    >
    afterUpdate: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: InstanceUpdateOptions<any>,
        ) => AsyncHookReturn,
    >
    afterUpsert: LegacyAddHookFunction<
        (
            attributes: [Model<any, any>, boolean | null],
            options: UpsertOptions<any>,
        ) => AsyncHookReturn,
    >
    afterValidate: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: ValidationOptions,
        ) => AsyncHookReturn,
    >
    beforeAssociate: LegacyAddHookFunction<
        (
            data: BeforeAssociateEventData,
            options: AssociationOptions<any>,
        ) => AsyncHookReturn,
    >
    beforeBulkCreate: LegacyAddHookFunction<
        (
            instances: Model<any, any>[],
            options: BulkCreateOptions<any>,
        ) => AsyncHookReturn,
    >
    beforeBulkDestroy: LegacyAddHookFunction<
        (options: DestroyOptions<any>) => AsyncHookReturn,
    >
    beforeBulkRestore: LegacyAddHookFunction<
        (options: RestoreOptions<any>) => AsyncHookReturn,
    >
    beforeBulkUpdate: LegacyAddHookFunction<
        (options: UpdateOptions<any>) => AsyncHookReturn,
    >
    beforeCount: LegacyAddHookFunction<
        (options: WritableObjectDeep<CountOptions<any>>) => AsyncHookReturn,
    >
    beforeCreate: LegacyAddHookFunction<
        (
            attributes: Model<any, any>,
            options: CreateOptions<any>,
        ) => AsyncHookReturn,
    >
    beforeDestroy: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: InstanceDestroyOptions,
        ) => AsyncHookReturn,
    >
    beforeFind: LegacyAddHookFunction<
        (options: WritableObjectDeep<FindOptions<any>>) => AsyncHookReturn,
    >
    beforeFindAfterExpandIncludeAll: LegacyAddHookFunction<
        (options: WritableObjectDeep<FindOptions<any>>) => AsyncHookReturn,
    >
    beforeFindAfterOptions: LegacyAddHookFunction<
        (options: WritableObjectDeep<FindOptions<any>>) => AsyncHookReturn,
    >
    beforeRestore: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: InstanceRestoreOptions,
        ) => AsyncHookReturn,
    >
    beforeSave: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: CreateOptions<any> | InstanceUpdateOptions<any>,
        ) => AsyncHookReturn,
    >
    beforeUpdate: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: InstanceUpdateOptions<any>,
        ) => AsyncHookReturn,
    >
    beforeUpsert: LegacyAddHookFunction<
        (
            attributes: Model<any, any>,
            options: UpsertOptions<any>,
        ) => AsyncHookReturn,
    >
    beforeValidate: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: ValidationOptions,
        ) => AsyncHookReturn,
    >
    hasHook: <HookName extends keyof ModelHooks<Model<any, any>, any>>(
        this: { hooks: HookHandler<ModelHooks<Model<any, any>, any>> },
        hookName: HookName,
    ) => boolean
    hasHooks: <HookName extends keyof ModelHooks<Model<any, any>, any>>(
        this: { hooks: HookHandler<ModelHooks<Model<any, any>, any>> },
        hookName: HookName,
    ) => boolean
    removeHook: <HookName extends keyof ModelHooks<Model<any, any>, any>>(
        this: { hooks: HookHandler<ModelHooks<Model<any, any>, any>> },
        hookName: HookName,
        listenerNameOrListener: string | ModelHooks<Model<any, any>, any>[HookName],
    ) => void
    runHooks: LegacyRunHookFunction<ModelHooks<Model<any, any>, any>, void>
    validationFailed: LegacyAddHookFunction<
        (
            instance: Model<any, any>,
            options: ValidationOptions,
            error: unknown,
        ) => AsyncHookReturn,
    >
    • get sequelize(): Sequelize

      A reference to the sequelize instance.

      Returns Sequelize

    • get associations(): {
          [associationName: string]: Association<
              Model<any, any>,
              Model<any, any>,
              string,
              NormalizedAssociationOptions<string>,
          >;
      }

      An object hash from alias to the association object

      Returns {
          [associationName: string]: Association<
              Model<any, any>,
              Model<any, any>,
              string,
              NormalizedAssociationOptions<string>,
          >;
      }

    • get hooks(): HookHandler<ModelHooks<Model<any, any>, any>>

      Returns HookHandler<ModelHooks<Model<any, any>, any>>

    • get modelDefinition(): ModelDefinition

      Returns the model definition of this model. The model definition contains all metadata about this model.

      Returns ModelDefinition

    • get primaryKeyAttribute(): string | null

      The name of the primary key attribute (on the JS side).

      Returns string | null

      This property doesn't work for composed primary keys. Use primaryKeyAttributes instead.

    • get primaryKeyAttributes(): string[]

      The name of the primary key attributes (on the JS side).

      Returns string[]

      use modelDefinition.

    • get primaryKeyField(): string | null

      The column name of the primary key.

      Returns string | null

      don't use this. It doesn't work with composite PKs. It may be removed in the future to reduce duplication. Use the. Use Model.primaryKeys instead.

    • get sequelize(): Sequelize

      A reference to the sequelize instance.

      Accessing this property throws if the model has not been registered with a Sequelize instance yet.

      Returns Sequelize

    • get tableName(): string

      The name of the database table

      Returns string

      use modelDefinition or table.

    • get uniqueKeys(): any

      Unique indexes that can be declared as part of a CREATE TABLE query.

      Returns any

      prefer using getIndexes, this will eventually be removed.

    • Returns void

    • Search for a single instance by its primary key.

      This applies LIMIT 1, only a single instance will be returned.

      Returns the model with the matching primary key. If not found, returns null or throws an error if FindOptions.rejectOnEmpty is set.

      Type Parameters

      Parameters

      Returns Promise<R | null>

    • Search for a single instance by its primary key.

      This applies LIMIT 1, only a single instance will be returned.

      Returns the model with the matching primary key. If not found, returns null or throws an error if FindOptions.rejectOnEmpty is set.

      Type Parameters

      Parameters

      Returns Promise<R>

    • Search for a single instance by its primary key.

      This applies LIMIT 1, only a single instance will be returned.

      Returns the model with the matching primary key. If not found, returns null or throws an error if FindOptions.rejectOnEmpty is set.

      Type Parameters

      • M extends Model<any, any>

      Parameters

      Returns Promise<M>

    • Search for a single instance by its primary key.

      This applies LIMIT 1, only a single instance will be returned.

      Returns the model with the matching primary key. If not found, returns null or throws an error if FindOptions.rejectOnEmpty is set.

      Type Parameters

      • M extends Model<any, any>

      Parameters

      Returns Promise<M | null>

    • Initialize a model, representing a table in the DB, with attributes and options.

      The table columns are defined by the hash that is given as the first argument. Each attribute of the hash represents a column.

      Type Parameters

      Parameters

      • this: MS
      • attributes: ModelAttributes<
            M,
            PartialBy<
                Attributes<M>,
                BrandedKeysOf<Attributes<M>, typeof ForeignKeyBrand>,
            >,
        >

        An object, where each attribute is a column of the table. Each column can be either a DataType, a string or a type-description object.

      • options: InitOptions<M>

        These options are merged with the default define options provided to the Sequelize constructor

      Returns MS

      Project.init({
      columnA: {
      type: DataTypes.BOOLEAN,
      validate: {
      is: ['[a-z]','i'], // will only allow letters
      max: 23, // only allow values <= 23
      isIn: {
      args: [['en', 'zh']],
      msg: "Must be English or Chinese"
      }
      },
      field: 'column_a'
      // Other attributes here
      },
      columnB: DataTypes.STRING,
      columnC: 'MY VERY OWN COLUMN TYPE'
      }, {sequelize})

      sequelize.models.modelName // The model will now be available in models under the class name

    • Returns boolean

    • Refreshes the Model's attribute definition.

      Returns void

      use modelDefinition.