Skip to content

postgrelize / Association

Abstract Class: Association<S, T> ​

Defined in: src/associations/association.ts:39

Association between two models (Sequelize v6 Association). Subclasses resolve the keys, add the foreign key attributes and implement the accessor methods that are installed on the source prototype (getX, setX, createX, ...).

Example ​

ts
const association: Association<Post, User> = Post.belongsTo(User);
association.associationType; // 'BelongsTo'

Type Parameters ​

S ​

S extends AnyModel = AnyModel

Instance type of the source model.

T ​

T extends AnyModel = AnyModel

Instance type of the target model.

Implements ​

  • Association

Constructors ​

Constructor ​

protected new Association<S, T>(type, source, target, options, name, keys): Association<S, T>

Defined in: src/associations/association.ts:88

Creates the association description; subclasses call install() afterwards.

Parameters ​

type ​

AssociationType

Kind of association.

source ​

ModelStatic<S>

Model the association is defined on.

target ​

ModelStatic<T>

Associated model.

options ​

AssociationOptions

Association options.

name ​

AssociationName

Singular and plural alias forms.

keys ​

AssociationKeyFields

Resolved keys.

Returns ​

Association<S, T>

Properties ​

accessors ​

readonly accessors: Readonly<Record<string, string>>

Defined in: src/associations/association.ts:62

Names of the instance methods added to the source model.

Implementation of ​

AssociationFields.accessors


as ​

readonly as: string

Defined in: src/associations/association.ts:50

Alias used in include and as the instance property.

Implementation of ​

AssociationFields.as


associationType ​

readonly associationType: AssociationType

Defined in: src/associations/association.ts:44

Kind of association.

Implementation of ​

AssociationFields.associationType


foreignKey ​

readonly foreignKey: string

Defined in: src/associations/association.ts:66

Foreign key attribute (on the source for belongsTo, on the target for hasOne/hasMany, on the junction for belongsToMany).

Implementation of ​

AssociationFields.foreignKey


identifierField ​

readonly identifierField: string

Defined in: src/associations/association.ts:68

Column of the foreign key.

Implementation of ​

AssociationFields.identifierField


isAliased ​

readonly isAliased: boolean

Defined in: src/associations/association.ts:54

Whether as was given explicitly.

Implementation of ​

AssociationFields.isAliased


isMultiAssociation ​

readonly isMultiAssociation: boolean

Defined in: src/associations/association.ts:60

True for hasMany / belongsToMany.

Implementation of ​

AssociationFields.isMultiAssociation


isSingleAssociation ​

readonly isSingleAssociation: boolean

Defined in: src/associations/association.ts:58

True for belongsTo / hasOne.

Implementation of ​

AssociationFields.isSingleAssociation


name ​

readonly name: AssociationName

Defined in: src/associations/association.ts:52

Singular and plural alias forms.

Implementation of ​

AssociationFields.name


options ​

readonly options: AssociationOptions

Defined in: src/associations/association.ts:64

Options the association was defined with.

Implementation of ​

AssociationFields.options


otherKey ​

readonly otherKey: string | undefined

Defined in: src/associations/association.ts:74

Junction foreign key pointing at the target (belongsToMany).

Implementation of ​

AssociationFields.otherKey


scope ​

readonly scope: Readonly<Record<string, unknown>> | undefined

Defined in: src/associations/association.ts:56

Association scope.

Implementation of ​

AssociationFields.scope


source ​

readonly source: ModelStatic<S>

Defined in: src/associations/association.ts:46

Model the association is defined on.

Implementation of ​

AssociationFields.source


sourceKey ​

readonly sourceKey: string

Defined in: src/associations/association.ts:70

Source attribute referenced by the foreign key.

Implementation of ​

AssociationFields.sourceKey


target ​

readonly target: ModelStatic<T>

Defined in: src/associations/association.ts:48

Associated model.

Implementation of ​

AssociationFields.target


targetKey ​

readonly targetKey: string

Defined in: src/associations/association.ts:72

Target attribute referenced by the foreign key (belongsTo) or by otherKey (belongsToMany).

Implementation of ​

AssociationFields.targetKey


through ​

readonly through: Readonly<{ model: ModelStatic<AnyModel>; scope?: Readonly<Record<string, unknown>>; }> | undefined

Defined in: src/associations/association.ts:76

Junction model (belongsToMany).

Implementation of ​

AssociationFields.through

Released under the MIT License.