diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index d7cbe2158..d8893524f 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -237,8 +237,416 @@ declare module "sequelize" { (values?: TAttributes, options?: HasOneCreateAssociationMixinOptions): Promise } + /** + * 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, UserAttributes { + * getRoles: Sequelize.HasManyGetAssociationsMixin; + * // setRoles... + * // addRoles... + * // addRole... + * // createRole... + * // removeRole... + * // removeRoles... + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyGetAssociationsMixin { + /** + * Get everything currently associated with this, using an optional where clause. + * @param options The options to use when getting the associations. + */ + (options?: HasManyGetAssociationsMixinOptions): Promise + } + + /** + * 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, UserAttributes { + * // getRoles... + * setRoles: Sequelize.HasManySetAssociationsMixin; + * // addRoles... + * // addRole... + * // createRole... + * // removeRole... + * // removeRoles... + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManySetAssociationsMixin { + /** + * 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, options?: HasManySetAssociationsMixinOptions): Promise + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * addRoles: Sequelize.HasManyAddAssociationsMixin; + * // addRole... + * // createRole... + * // removeRole... + * // removeRoles... + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyAddAssociationsMixin { + /** + * 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, options?: HasManyAddAssociationsMixinOptions): Promise + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * // addRoles... + * addRole: Sequelize.HasManyAddAssociationMixin; + * // createRole... + * // removeRole... + * // removeRoles... + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyAddAssociationMixin { + /** + * 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 + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * // addRoles... + * // addRole... + * createRole: Sequelize.HasManyCreateAssociationMixin; + * // removeRole... + * // removeRoles... + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyCreateAssociationMixin { + /** + * 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 + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * // addRoles... + * // addRole... + * // createRole... + * removeRole: Sequelize.HasManyRemoveAssociationMixin; + * // removeRoles... + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyRemoveAssociationMixin { + /** + * 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 + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * // addRoles... + * // addRole... + * // createRole... + * // removeRole... + * removeRoles: Sequelize.HasManyRemoveAssociationsMixin; + * // hasRole... + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyRemoveAssociationsMixin { + /** + * 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, options?: HasManyRemoveAssociationsMixinOptions): Promise + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * // addRoles... + * // addRole... + * // createRole... + * // removeRole... + * // removeRoles... + * hasRole: Sequelize.HasManyHasAssociationMixin; + * // hasRoles... + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyHasAssociationMixin { + /** + * 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 + } + + /** + * 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, UserAttributes { + * // getRoles... + * // setRoles... + * // addRoles... + * // addRole... + * // createRole... + * // removeRole... + * // removeRoles + * // hasRole... + * hasRoles: Sequelize.HasManyHasAssociationsMixin; + * // countRoles... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ + * @see Instance + */ + interface HasManyHasAssociationsMixin { + /** + * 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, options?: HasManyHasAssociationsMixinOptions): Promise + } + + /** + * 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, 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 + } - // TODO: HasMany Associations // TODO: BelongsToMany Associations /**