Documentation

gitHub

Derive a one-to-one conceptual relationship

Let's extend the example of Derive a one-to-many conceptual relationship with an Invoice entity.

 

Example: Order and Invoice

Each invoice is issued for exactly one order (cardinality 1 on the Order side), and an order has at most one invoice (cardinality 0..1 on the Invoice side, assuming no backorder capability in this example):

 

Polyglot ER diagram with Order and Invoice linked by is invoiced by, and the Properties pane of the relationship with cardinality 1 for Order and 0..1 for Invoice

 

In a one-to-one relationship, the foreign key attributes are created on the optional side. Hackolade Studio adds a required Order_id column to the Invoice table, and also creates a unique key on this column, so that the same order cannot be invoiced twice. When there are several foreign key columns, the unique key is created on all of them together. No unique key is added when these columns already form the complete primary key of the Invoice table.

 

Derived PostgreSQL model with the generated order_id column in invoice, marked uk and fk, and its Properties pane with Unique checked

 

Same cardinality on both sides

When both sides have the same cardinality (1 and 1, or 0..1 and 0..1), both choices are valid from a modeling point of view. Hackolade Studio then applies a convention: the foreign key attributes are created in the second entity listed in the Linked entities section of the relationship's properties.

 

Conceptual model - swap entities in relationship

 

Tip

To get the foreign key attributes in the other entity, swap the two entities in the Linked entities section of the relationship's properties before deriving, with the arrows described in Direction as a semantic choice.

 

Summary: cardinality impact on placement of foreign key

The child entity and the parent entity are determined according to the logic in this table:

 

RelationshipChild entityParent entity
One-to-manyThe entity on the "many" side (0..n or 1..n)The entity on the "one" side (1 or 0..1)
One-to-zero-to-one, 1 on one side and 0..1 on the otherThe entity with cardinality 0..1The entity with cardinality 1
One-to-one, same cardinality on both sidesThe second entity in the Linked entities listThe first entity in the Linked entities list