Let's assume there is some information in a table:
+-----------------+ | node | +--+--------------+ |PK| id | +--+--------------+ | | other fields | | | ... | | | | unstructured nodes
To turn this table into a tree, you need to add a foreign key:
+-----------------+ | node | +--+--------------+ ->|PK| id | | +--+--------------+ --|FK| parent_id | | | other fields | | | ... | | | | a simple tree
To turn this table into a directed graph, where each node may have zero or more children and one or more parents, you need a many-to-many relationship:
+------------------+ +-----------------+ | arch | | node | +------------------| +--+--------------+ |PK| id | --->|PK| id | +------------------+ / / +--+--------------+ |FK|parent_node_id |--- / | | other fields | |FK|child_node_id |---- | | ... | +--+---------------+ | | | a simple d-graph
To impose hierarchy rules on a tree, nodes must be typed, and a list of legal parent-child relationships must exist.
+-----------------+ | node | +--+--------------+ ->|PK| id | | +--+--------------+ --|FK| parent_id | ---|FK| arch_type_id | / --|FK| type_id | | | | | other fields | | | | | ... | | | | | +-----------------------+ | | +-----------------+ | arch_type | | | | node_type | +--+--------------------+ / | +--+--------------+ |PK| id |<- --->|PK| id | +--+--------------------+ / / +--+--------------+ |FK| parent_node_type_id|--- / | | other fields | |FK| child_node_type_id |---- | | ... | +--+--------------------+ | | | a structured tree
To impose hierarchy rules on a directed graph, nodes and arches must be typed, and a list of legal parent-child relationships must exist.
+-------------------+ +-----------------+ | arch | | node | +--+----------------+ +--+--------------+ |PK| id | ------->|PK| id | +--+----------------+ / / +--+--------------+ |FK| parent_node_id |--- / ---|FK| arch_type_id | |FK| child_node_id |---- / --|FK| type_id | --|FK| type_id | | | | | other fields | | +--+----------------+ | | | | ... | | | | | | | | | | | | | | +-----------------------+ | | +-----------------+ | | arch_type | | | | node_type | | +--+--------------------+ / | +--+--------------+ ->|PK| id |<- --->|PK| id | +--+--------------------+ / / +--+--------------+ |FK| parent_node_type_id|--- / | | other fields | |FK| child_node_type_id |---- | | ... | +--+--------------------+ | | | a structured directed graph