Foreign key between source table and target table.
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)
Whether the relation targets to many. Since, one to many relations targets many, this is true
.
Type of the relation, which is o2m
for O2MRelation.
For TypeScript it is enum of RelationType.O2M
.
Informational text representation of the relation.
const info = relation.info; // [public.contact]――― cart_contact ――⥷ [public.cart]
Suggested name for relation.
Source table's adjective extracted from foreign key name.
Source table alias
Source table name.
Source table's adjective extracted from foreign key name.
Target table alias
Target table name
Retunrs name for the relation using given naming function.
are custom functions or name of the modulethat exports relation name functions to generate names with. pg-structure
provides some builtin modules (short
, optimal
and descriptive
), but you can use your own.
name for the relation using naming function.
Returns source table alias after replacing given tables' names from it.
is type or types of tables to exclude names of.
source table alias after given tables' names replaced.
Returns source table name after replacing given tables' names from it.
is type or types of tables to exclude names of.
source table name after given tables' names replaced.
Returns target table alias after replacing given tables' names from it.
is type or types of tables to exclude names of.
target table alias after given tables' names replaced.
Returns target table name after replacing given tables' names from it.
is type or types of tables to exclude names of.
target table name after given tables' names replaced.
Generated using TypeDoc
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:
Some definitions used in descriptions for O2MRelation.
Example
```typescript // 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) ```