diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index ba465db5e7..ba8d03d94b 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -20,6 +20,110 @@ declare module "sequelize" { // https://github.com/sequelize/sequelize/tree/v3.4.1/lib/associations // + + /** + * The options for the get mixin of the BelongsTo association. + * @see BelongsToAssociationGetMixin + */ + interface BelongsToAssociationGetMixinOptions { + /** + * Apply a scope on the related model, or remove its default scope by passing false. + */ + scope: string | boolean; + } + + /** + * The get association mixin applied to models with BelongsTo. + * An example of usage is as follows: + * + * ```js + * interface UserInstance extends Sequelize.Instance, UserAttrib { + * getRole: Sequelize.BelongsToAssociationGetMixin; + * // setRole... + * // createRole... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/ + * @see Instance + */ + interface BelongsToAssociationGetMixin { + /** + * Get the associated instance. + * @param options The obtions to use when getting the association. + */ + (options?: BelongsToAssociationGetMixinOptions): Promise + } + + /** + * The options for the set mixin of the BelongsTo association. + * @see BelongsToAssociationSetMixin + */ + interface BelongsToAssociationSetMixinOptions { + /** + * Skip saving this after setting the foreign key if false. + */ + save: boolean; + } + + /** + * The set association mixin applied to models with BelongsTo. + * An example of usage is as follows: + * + * ```js + * interface UserInstance extends Sequelize.Instance, UserAttributes { + * // getRole... + * setRole: BelongsToAssociationSetMixin; + * // createRole... + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/ + * @see Instance + */ + interface BelongsToAssociationSetMixin { + /** + * Get the associated instance. + * @param newAssociation An instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association. + * @param options The obtions to use when setting the association. + */ + (newAssociation: TInstance | TInstancePrimaryKey, options?: BelongsToAssociationSetMixinOptions): Promise + } + + /** + * The options for the create mixin of the BelongsTo association. + * @see BelongsToAssociationCreateMixin + */ + interface BelongsToAssociationCreateMixinOptions extends CreateOptions, BelongsToAssociationSetMixinOptions {} + + /** + * The create association mixin applied to models with BelongsTo. + * An example of usage is as follows: + * + * ```js + * interface UserInstance extends Sequelize.Instance, UserAttributes { + * // getRole... + * // setRole... + * createRole: BelongsToAssociationCreateMixin; + * } + * ``` + * + * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/ + * @see Instance + */ + interface BelongsToAssociationCreateMixin { + /** + * 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 passed to `target.create` and `setAssociation`. + */ + (values?: TAttributes, options?: BelongsToAssociationCreateMixinOptions): Promise + } + + // TODO: HasOne Associations + // TODO: HasMany Associations + // TODO: BelongsToMany Associations + /** * Foreign Key Options *