mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Added hasMany associations
This commit is contained in:
Vendored
+409
-1
@@ -237,8 +237,416 @@ declare module "sequelize" {
|
||||
(values?: TAttributes, options?: HasOneCreateAssociationMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the getAssociations mixin of the hasMany association.
|
||||
* @see HasManyGetAssociationsMixin
|
||||
*/
|
||||
interface HasManyGetAssociationsMixinOptions {
|
||||
|
||||
/**
|
||||
* An optional where clause to limit the associated models.
|
||||
*/
|
||||
where?: WhereOptions;
|
||||
|
||||
/**
|
||||
* Apply a scope on the related model, or remove its default scope by passing false.
|
||||
*/
|
||||
scope?: 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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* getRoles: Sequelize.HasManyGetAssociationsMixin<RoleInstance>;
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyGetAssociationsMixin<TInstance> {
|
||||
/**
|
||||
* Get everything currently associated with this, using an optional where clause.
|
||||
* @param options The options to use when getting the associations.
|
||||
*/
|
||||
(options?: HasManyGetAssociationsMixinOptions): Promise<TInstance[]>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the setAssociations mixin of the hasMany association.
|
||||
* @see HasManySetAssociationsMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* setRoles: Sequelize.HasManySetAssociationsMixin<RoleInstance, RoleId>;
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManySetAssociationsMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Set the associated models by passing an array of instances or their primary keys.
|
||||
* Everything that it not in the passed array will be un-associated.
|
||||
* @param newAssociations An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations.
|
||||
* @param options The options to use when setting the associations.
|
||||
*/
|
||||
(newAssociations?: Array<TInstance | TInstancePrimaryKey>, options?: HasManySetAssociationsMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the addAssociations mixin of the hasMany association.
|
||||
* @see HasManyAddAssociationsMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* addRoles: Sequelize.HasManyAddAssociationsMixin<RoleInstance, RoleId>;
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyAddAssociationsMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Associate several instances with this.
|
||||
* @param newAssociations An array of instances or primary key of instances to associate with this.
|
||||
* @param options The options to use when adding the associations.
|
||||
*/
|
||||
(newAssociations?: Array<TInstance | TInstancePrimaryKey>, options?: HasManyAddAssociationsMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the addAssociation mixin of the hasMany association.
|
||||
* @see HasManyAddAssociationMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* addRole: Sequelize.HasManyAddAssociationMixin<RoleInstance, RoleId>;
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyAddAssociationMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Associate an instance with this.
|
||||
* @param newAssociation An instance or the primary key of an instance to associate with this.
|
||||
* @param options The options to use when adding the association.
|
||||
*/
|
||||
(newAssociation?: TInstance | TInstancePrimaryKey, options?: HasManyAddAssociationMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the createAssociation mixin of the hasMany association.
|
||||
* @see HasManyCreateAssociationMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* createRole: Sequelize.HasManyCreateAssociationMixin<RoleAttributes>;
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyCreateAssociationMixin<TAttributes> {
|
||||
/**
|
||||
* Create a new instance of the associated model and associate it with this.
|
||||
* @param values The values used to create the association.
|
||||
* @param options The options to use when adding the association.
|
||||
*/
|
||||
(values?: TAttributes, options?: HasManyCreateAssociationMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the removeAssociation mixin of the hasMany association.
|
||||
* @see HasManyRemoveAssociationMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* removeRole: Sequelize.HasManyRemoveAssociationMixin<RoleInstance, RoleId>;
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyRemoveAssociationMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Un-associate the instance.
|
||||
* @param oldAssociated The instance or the primary key of the instance to un-associate.
|
||||
* @param options The options to use when removing the association.
|
||||
*/
|
||||
(oldAssociated?: TInstance | TInstancePrimaryKey, options?: HasManyRemoveAssociationMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the removeAssociations mixin of the hasMany association.
|
||||
* @see HasManyRemoveAssociationsMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* removeRoles: Sequelize.HasManyRemoveAssociationsMixin<RoleInstance, RoleId>;
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyRemoveAssociationsMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Un-associate several instances.
|
||||
* @param oldAssociated An array of instances or primary key of instances to un-associate.
|
||||
* @param options The options to use when removing the associations.
|
||||
*/
|
||||
(oldAssociateds?: Array<TInstance | TInstancePrimaryKey>, options?: HasManyRemoveAssociationsMixinOptions): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the hasAssociation mixin of the hasMany association.
|
||||
* @see HasManyHasAssociationMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* hasRole: Sequelize.HasManyHasAssociationMixin<RoleInstance, RoleId>;
|
||||
* // hasRoles...
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyHasAssociationMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Check if an instance is associated with this.
|
||||
* @param target The instance or the primary key of the instance to check.
|
||||
* @param options The options to use when checking the association.
|
||||
*/
|
||||
(target: TInstance | TInstancePrimaryKey, options?: HasManyHasAssociationMixinOptions): Promise<boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the hasAssociations mixin of the hasMany association.
|
||||
* @see HasManyHasAssociationsMixin
|
||||
*/
|
||||
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<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles
|
||||
* // hasRole...
|
||||
* hasRoles: Sequelize.HasManyHasAssociationsMixin<RoleInstance, RoleId>;
|
||||
* // countRoles...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyHasAssociationsMixin<TInstance, TInstancePrimaryKey> {
|
||||
/**
|
||||
* Check if all instances are associated with this.
|
||||
* @param targets An array of instances or primary key of instances to check.
|
||||
* @param options The options to use when checking the associations.
|
||||
*/
|
||||
(targets?: Array<TInstance | TInstancePrimaryKey>, options?: HasManyHasAssociationsMixinOptions): Promise<boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the countAssociations mixin of the hasMany association.
|
||||
* @see HasManyCountAssociationsMixin
|
||||
*/
|
||||
interface HasManyCountAssociationsMixinOptions extends HasManyGetAssociationsMixinOptions { }
|
||||
|
||||
/**
|
||||
* The countAssociations mixin applied to models with hasMany.
|
||||
* An example of usage is as follows:
|
||||
*
|
||||
* ```js
|
||||
*
|
||||
* User.hasMany(Role);
|
||||
*
|
||||
* interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
|
||||
* // getRoles...
|
||||
* // setRoles...
|
||||
* // addRoles...
|
||||
* // addRole...
|
||||
* // createRole...
|
||||
* // removeRole...
|
||||
* // removeRoles...
|
||||
* // hasRole...
|
||||
* // hasRoles...
|
||||
* countRoles: Sequelize.HasManyCountAssociationsMixin;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
|
||||
* @see Instance
|
||||
*/
|
||||
interface HasManyCountAssociationsMixin {
|
||||
/**
|
||||
* Count everything currently associated with this, using an optional where clause.
|
||||
* @param options The options to use when counting the associations.
|
||||
*/
|
||||
(options?: HasManyCountAssociationsMixinOptions): Promise<number>
|
||||
}
|
||||
|
||||
// TODO: HasMany Associations
|
||||
// TODO: BelongsToMany Associations
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user