# Class: O2MRelation

Class which represent one to many relationship which resembles hasMany relation in ORMs (Object Relational Mappers). Provides attributes and methods for details of the relationship.

Below is a database schema as an example: Database Schema

Some definitions used in descriptions for O2MRelation.

  • ** Source Table: ** Table which this relationship belongs to.
  • ** Target Table: ** Table that is related to base table.#### Example
// Example tables have single primary key and examples first relation. So zero index ([0]) is used. Use all array elements if necessary.
// product ----< line_item
// (source)       (target)

const relation         = product.o2mRelations[0];              // RELATION:    product ---< line_item
const foreignKey       = relation.foreignKey;                  // FOREIGN KEY:          ^-- product_has_carts
const sourceTable      = relation.sourceTable;                 // TABLE:       product
const targetTable      = relation.targetTable;                 // TABLE:       line_item
const FKColumn         = relation.foreignKey.columns[0];       // COLUMN:      product_id  (from line_item table)
const sourcePKColumn   = relation.sourceTable.primaryKeys[0];  // COLUMN:      id          (from product table)

# Hierarchy

# Properties

# foreignKey

foreignKey: ForeignKey

Overrides void

Defined in pg-structure/relation/o2m-relation.ts:80

Foreign key between source table and target table.

# Example

const relation     = product.O2MRelationRelations[0];  // RELATION:    product ---< line_item
const foreignKey   = relation.foreignKey;              // CONSTRAINT:           ^-- product_has_carts
const FKColumn     = relation.foreignKey.columns[0];   // COLUMN:      product_id (from line_item table)

# Accessors

# info

get info(): string

Overrides void

Defined in pg-structure/relation/o2m-relation.ts:46

Informational text representation of the relation.

# Example

const info = relation.info; // [public.contact]――― cart_contact ――⥷ [public.cart]

Returns: string


# name

get name(): string

Inherited from Relation.name

Defined in pg-structure/base/relation.ts:100

Suggested name for relation.

see {@link ../relation-names.md Relation Names}

Returns: string


# sourceAdjective

get sourceAdjective(): string | undefined

Inherited from Relation.sourceAdjective

Defined in pg-structure/base/relation.ts:85

Source table's adjective extracted from foreign key name.

Returns: string | undefined


# sourceAlias

get sourceAlias(): string

Defined in pg-structure/relation/o2m-relation.ts:103

Source table alias

Returns: string


# sourceName

get sourceName(): string

Inherited from Relation.sourceName

Defined in pg-structure/base/relation.ts:75

Source table name.

Returns: string


# sourceTable

get sourceTable(): Table

Overrides void

Defined in pg-structure/relation/o2m-relation.ts:57

Table which this relation belongs to.

# Example

const relation     = product.O2MRelationRelations[0];  // RELATION:    product ---< line_item
const sourceTable  = relation.sourceTable;             // TABLE:       product

Returns: Table


# targetAdjective

get targetAdjective(): string | undefined

Inherited from Relation.targetAdjective

Defined in pg-structure/base/relation.ts:90

Source table's adjective extracted from foreign key name.

Returns: string | undefined


# targetAlias

get targetAlias(): string

Defined in pg-structure/relation/o2m-relation.ts:108

Target table alias

Returns: string


# targetName

get targetName(): string

Inherited from Relation.targetName

Defined in pg-structure/base/relation.ts:80

Target table name

Returns: string


# targetTable

get targetTable(): Table

Overrides void

Defined in pg-structure/relation/o2m-relation.ts:68

Table which this relation is referring to.

# Example

const relation     = product.O2MRelationRelations[0];  // RELATION:    product ---< line_item
const targetTable  = relation.targetTable;             // TABLE:       line_item

Returns: Table

# Methods

# getName

getName(relationNameFunction: RelationNameFunction | BuiltinRelationNameFunction): string

Inherited from Relation.getName

Defined in pg-structure/base/relation.ts:112

Retunrs name for the relation using given naming function.

Parameters:

Name Type Description
relationNameFunction RelationNameFunction | BuiltinRelationNameFunction is custom function or name of the builtin function to generate names with.

Returns: string

name for the relation using naming function.


# getSourceAliasWithout

getSourceAliasWithout(without: RelationWithout | RelationWithout[]): string

Defined in pg-structure/relation/o2m-relation.ts:88

Returns source table alias after replacing given tables' names from it.

Parameters:

Name Type Description
without RelationWithout | RelationWithout[] is type or types of tables to exclude names of.

Returns: string

source table alias after given tables' names replaced.


# getSourceNameWithout

getSourceNameWithout(without: RelationWithout | RelationWithout[]): string

Inherited from Relation.getSourceNameWithout

Defined in pg-structure/base/relation.ts:60

Returns source table name after replacing given tables' names from it.

Parameters:

Name Type Description
without RelationWithout | RelationWithout[] is type or types of tables to exclude names of.

Returns: string

source table name after given tables' names replaced.


# getTargetAliasWithout

getTargetAliasWithout(without: RelationWithout | RelationWithout[]): string

Defined in pg-structure/relation/o2m-relation.ts:98

Returns target table alias after replacing given tables' names from it.

Parameters:

Name Type Description
without RelationWithout | RelationWithout[] is type or types of tables to exclude names of.

Returns: string

target table alias after given tables' names replaced.


# getTargetNameWithout

getTargetNameWithout(without: RelationWithout | RelationWithout[]): string

Inherited from Relation.getTargetNameWithout

Defined in pg-structure/base/relation.ts:70

Returns target table name after replacing given tables' names from it.

Parameters:

Name Type Description
without RelationWithout | RelationWithout[] is type or types of tables to exclude names of.

Returns: string

target table name after given tables' names replaced.