import { DataType } from '../data-types'; import { CreateOptions, CreationAttributes, Filterable, FindOptions, InstanceUpdateOptions, Model, ModelCtor, Transactionable, } from '../model'; import { Association, ManyToManyOptions, MultiAssociationAccessors } from './base'; /** * Options provided when associating models with hasMany relationship */ export interface HasManyOptions extends ManyToManyOptions { /** * The name of the field to use as the key for the association in the source table. Defaults to the primary * key of the source table */ sourceKey?: string; /** * A string or a data type to represent the identifier in the table */ keyType?: DataType; } export class HasMany extends Association { public accessors: MultiAssociationAccessors; constructor(source: ModelCtor, target: ModelCtor, options: HasManyOptions); } /** * The options for the getAssociations mixin of the hasMany association. * @see HasManyGetAssociationsMixin */ export interface HasManyGetAssociationsMixinOptions extends FindOptions { /** * Apply a scope on the related model, or remove its default scope by passing false. */ scope?: string | string[] | boolean; } /** * The getAssociations mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * getRoles: Sequelize.HasManyGetAssociationsMixin; * // setRoles... * // addRoles... * // addRole... * // createRole... * // removeRole... * // removeRoles... * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyGetAssociationsMixin = (options?: HasManyGetAssociationsMixinOptions) => Promise; /** * The options for the setAssociations mixin of the hasMany association. * @see HasManySetAssociationsMixin */ export interface HasManySetAssociationsMixinOptions extends FindOptions, InstanceUpdateOptions {} /** * The setAssociations mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * setRoles: Sequelize.HasManySetAssociationsMixin; * // addRoles... * // addRole... * // createRole... * // removeRole... * // removeRoles... * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManySetAssociationsMixin = ( newAssociations?: (TModel | TModelPrimaryKey)[], options?: HasManySetAssociationsMixinOptions ) => Promise; /** * The options for the addAssociations mixin of the hasMany association. * @see HasManyAddAssociationsMixin */ export interface HasManyAddAssociationsMixinOptions extends InstanceUpdateOptions {} /** * The addAssociations mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * addRoles: Sequelize.HasManyAddAssociationsMixin; * // addRole... * // createRole... * // removeRole... * // removeRoles... * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyAddAssociationsMixin = ( newAssociations?: (TModel | TModelPrimaryKey)[], options?: HasManyAddAssociationsMixinOptions ) => Promise; /** * The options for the addAssociation mixin of the hasMany association. * @see HasManyAddAssociationMixin */ export interface HasManyAddAssociationMixinOptions extends InstanceUpdateOptions {} /** * The addAssociation mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * addRole: Sequelize.HasManyAddAssociationMixin; * // createRole... * // removeRole... * // removeRoles... * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyAddAssociationMixin = ( newAssociation?: TModel | TModelPrimaryKey, options?: HasManyAddAssociationMixinOptions ) => Promise; /** * The options for the createAssociation mixin of the hasMany association. * @see HasManyCreateAssociationMixin */ export interface HasManyCreateAssociationMixinOptions extends CreateOptions {} /** * The createAssociation mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * // addRole... * createRole: Sequelize.HasManyCreateAssociationMixin; * // removeRole... * // removeRoles... * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyCreateAssociationMixin< TModel extends Model, TForeignKey extends keyof CreationAttributes = never, TScope extends keyof CreationAttributes = never > = ( values?: Omit, TForeignKey | TScope>, options?: HasManyCreateAssociationMixinOptions ) => Promise; /** * The options for the removeAssociation mixin of the hasMany association. * @see HasManyRemoveAssociationMixin */ export interface HasManyRemoveAssociationMixinOptions extends InstanceUpdateOptions {} /** * The removeAssociation mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * // addRole... * // createRole... * removeRole: Sequelize.HasManyRemoveAssociationMixin; * // removeRoles... * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyRemoveAssociationMixin = ( oldAssociated?: TModel | TModelPrimaryKey, options?: HasManyRemoveAssociationMixinOptions ) => Promise; /** * The options for the removeAssociations mixin of the hasMany association. * @see HasManyRemoveAssociationsMixin */ export interface HasManyRemoveAssociationsMixinOptions extends InstanceUpdateOptions {} /** * The removeAssociations mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * // addRole... * // createRole... * // removeRole... * removeRoles: Sequelize.HasManyRemoveAssociationsMixin; * // hasRole... * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyRemoveAssociationsMixin = ( oldAssociateds?: (TModel | TModelPrimaryKey)[], options?: HasManyRemoveAssociationsMixinOptions ) => Promise; /** * The options for the hasAssociation mixin of the hasMany association. * @see HasManyHasAssociationMixin */ export interface HasManyHasAssociationMixinOptions extends HasManyGetAssociationsMixinOptions {} /** * The hasAssociation mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * // addRole... * // createRole... * // removeRole... * // removeRoles... * hasRole: Sequelize.HasManyHasAssociationMixin; * // hasRoles... * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyHasAssociationMixin = ( target: TModel | TModelPrimaryKey, options?: HasManyHasAssociationMixinOptions ) => Promise; /** * The options for the hasAssociations mixin of the hasMany association. * @see HasManyHasAssociationsMixin */ export interface HasManyHasAssociationsMixinOptions extends HasManyGetAssociationsMixinOptions {} /** * The removeAssociations mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * // addRole... * // createRole... * // removeRole... * // removeRoles * // hasRole... * hasRoles: Sequelize.HasManyHasAssociationsMixin; * // countRoles... * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyHasAssociationsMixin = ( targets: (TModel | TModelPrimaryKey)[], options?: HasManyHasAssociationsMixinOptions ) => Promise; /** * The options for the countAssociations mixin of the hasMany association. * @see HasManyCountAssociationsMixin */ export interface HasManyCountAssociationsMixinOptions extends Transactionable, Filterable { /** * Apply a scope on the related model, or remove its default scope by passing false. */ scope?: string | boolean; } /** * The countAssociations mixin applied to models with hasMany. * An example of usage is as follows: * * ```js * * User.hasMany(Role); * * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRoles... * // setRoles... * // addRoles... * // addRole... * // createRole... * // removeRole... * // removeRoles... * // hasRole... * // hasRoles... * countRoles: Sequelize.HasManyCountAssociationsMixin; * } * ``` * * @see https://sequelize.org/master/class/lib/associations/has-many.js~HasMany.html * @see Instance */ export type HasManyCountAssociationsMixin = (options?: HasManyCountAssociationsMixinOptions) => Promise;