# Class: M2ORelation

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

Actually there is no many to one relation in database engine. It is basically one to many relation in reverse direction.

Below is a database schema as an example: Database Schema

Some definitions used in descriptions for M2ORelation.

  • ** 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.
// line_item >---- product
// (source)        (target)

const relation     = line_item.m2oRelations[0];            // RELATION:    line_item >---- product
const foreignKey   = relation.foreignKey;                  // CONSTRAINT:               ^-- product_has_carts
const sourceTable  = relation.sourceTable;                 // TABLE:       line_item
const targetTable  = relation.targetTable;                 // TABLE:       product
const FKColumn     = relation.foreignKey.columns[0];       // COLUMN:      product_id  (from line_item table)
const PKColumn     = relation.targetTable.primaryKeys[0];  // COLUMN:      id          (from product table)

# Hierarchy

# Properties

# foreignKey

foreignKey: ForeignKey

Overrides void

Defined in pg-structure/relation/m2o-relation.ts:82

{@link ForiegnKey Foreign key} between source table and target table.

# Example

const relation     = product.M2ORelationRelations[0];  // RELATION:    line_item >---- product
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/m2o-relation.ts:48

Informational text representation of the relation.

# Example

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

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/m2o-relation.ts:105

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/m2o-relation.ts:59

Table which this relation belongs to.

# Example

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

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/m2o-relation.ts:110

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/m2o-relation.ts:70

Table which this relation is referred by.

# Example

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

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/m2o-relation.ts:90

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/m2o-relation.ts:100

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.