# Class: ForeignKey

Class which represent a foreign key. Provides attributes and methods for details of the foreign key.

# Hierarchy

Constraint

ForeignKey

# Properties

# columns

columns: IndexableArray‹Column, "name", never, true›

Defined in pg-structure/constraint/foreign-key.ts:61

{@link IndexableArray Indexable array} of columns this foreign key has. Columns are in order their ordinal position within the foreign key.


# Optional comment

comment? : undefined | string

Inherited from DbObject.comment

Defined in pg-structure/base/db-object.ts:75

Comment of the database object defined in database including {@link DbObject#commentData comment data}.


# index

index: Index

Defined in pg-structure/constraint/foreign-key.ts:55

The @{link Index index}} supporting this constraint.


# matchType

matchType: MatchType

Defined in pg-structure/constraint/foreign-key.ts:38

Match option of ForeignKey. One of FULL, PARTIAL, NONE. TypeScript developers should use {@link MatchOption} enum.


# name

name: string

Inherited from DbObject.name

Defined in pg-structure/base/db-object.ts:42

Name of the database object.


# onDelete

onDelete: Action

Defined in pg-structure/constraint/foreign-key.ts:50

Delete action for foreign keys. One of CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION. TypeScript developers should use Action enumn.


# onUpdate

onUpdate: Action

Defined in pg-structure/constraint/foreign-key.ts:44

Update action for foreign keys. One of CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION. TypeScript developers should use Action enumn.


# table

table: Table

Defined in pg-structure/constraint/foreign-key.ts:95

Table which this constraint defined in.

# Accessors

# commentData

get commentData(): JSONData | undefined

Inherited from DbObject.commentData

Defined in pg-structure/base/db-object.ts:102

Data which is extracted from database object's comment. Data is extracted from text between special case-insesitive tag (default: [pg-structure][/pg-structure]) and converted to JavaScript object using JSON5. Token name can be specified by using commentDataToken arguments. For details of JSON5, see it's web site: https://json5.org.

# Example

// "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.comment;               // "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.commentWithoutData;    // "Account details.  Also used for logging."
table.commentData;           // { extraData: 2 }
table.commentData.extraData; // 2

Returns: JSONData | undefined


# commentWithoutData

get commentWithoutData(): string | undefined

Inherited from DbObject.commentWithoutData

Defined in pg-structure/base/db-object.ts:85

Description or comment of the database object defined in database. If comment contains {@link DbObject#commentData comment data}, it is removed.

# Example

// "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.commentWithoutData;    // "Account details.  Also used for logging."

Returns: string | undefined


# correspondingForeignKeys

get correspondingForeignKeys(): IndexableArray‹ForeignKey, "name", never, true›

Defined in pg-structure/constraint/foreign-key.ts:88

List of other foreign keys which has same source table and target table.

Returns: IndexableArray‹ForeignKey, "name", never, true›


# db

get db(): Db

Inherited from DbObject.db

Defined in pg-structure/base/db-object.ts:68

Database of the database object.

Returns: Db


# fullCatalogName

get fullCatalogName(): string

Inherited from DbObject.fullCatalogName

Defined in pg-structure/base/db-object.ts:35

Full name of the database object including database name.

Returns: string


# fullName

get fullName(): string

Overrides DbObject.fullName

Defined in pg-structure/constraint/foreign-key.ts:100

Full name of the constraint including table name.

Returns: string


# nameCaseType

get nameCaseType(): CaseType

Inherited from DbObject.nameCaseType

Defined in pg-structure/base/db-object.ts:54

Letter casing (i.e snakeCase or camelCase) of the database object name.

# Example

const name = entity.name;                        // ProductDetail
const caseType = entity.nameCaseType;            // camelCase

const otherEntity = otherEntity.name;            // member_protocol
const otherCaseType = otherEntity.nameCaseType;  // snakeCase

Returns: CaseType


# referencedColumns

get referencedColumns(): IndexableArray‹Column, "name", never, true›

Defined in pg-structure/constraint/foreign-key.ts:74

{@link IndexableArray Indexable array} of columns this foreign key refers. Columns are in order their ordinal position within the foreign key.

Returns: IndexableArray‹Column, "name", never, true›


# referencedColumnsBy

get referencedColumnsBy(): object[]

Defined in pg-structure/constraint/foreign-key.ts:81

Array of columns this foreign key has and refers to.

Returns: object[]


# referencedTable

get referencedTable(): Table

Defined in pg-structure/constraint/foreign-key.ts:66

This is Table instance this foreign key refers to.

Returns: Table


# schema

get schema(): Schema

Overrides DbObject.schema

Defined in pg-structure/constraint/foreign-key.ts:107

Schema of the constraint's table defined in.

Returns: Schema


# separator

get separator(): string

Inherited from DbObject.separator

Defined in pg-structure/base/db-object.ts:61

Separator used in database object name. Empty string for came case and underscore for (_) snake case.

Returns: string