From c8223d68d246f0ed71af83162148bf2024225611 Mon Sep 17 00:00:00 2001 From: Ali Taheri Date: Tue, 29 Sep 2015 13:20:24 +0330 Subject: [PATCH 1/2] [Sequelize] Added BelongsTo association mixin helper types. --- sequelize/sequelize.d.ts | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index ba465db5e7..6328f4917a 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 * From 7abab20604754400b1c7f43f97def8a5dc6f3556 Mon Sep 17 00:00:00 2001 From: Ali Taheri Date: Tue, 29 Sep 2015 13:42:02 +0330 Subject: [PATCH 2/2] Fixed a typo in create mixin's docs --- sequelize/sequelize.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 6328f4917a..ba8d03d94b 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -104,7 +104,7 @@ declare module "sequelize" { * interface UserInstance extends Sequelize.Instance, UserAttributes { * // getRole... * // setRole... - * createRole: BelongsToAssociationCreateMixin; + * createRole: BelongsToAssociationCreateMixin; * } * ``` *