I am looking for opinions on how to model a directed graph containing one special node.
Special node:
- There can be no ribs associated with it.
- Unable to delete.
Current construction:
Tables: Knots, Edges. The edges contain two columns; from_node_id and to_node_id, each of which refers to an entry in the Nodes table.
Instead of storing a special node as the first record in the Nodes table, I decided not to write it at all, creating it separately from any database queries. In the Edges table, NULL takes on a special value in the from_node_id column, referring to the center of the node.
My motivation for using this design was that I would not have to worry about protecting the node center record from being deleted / modified or referenced to the to_node_id column in the Edges table. It will also automatically prevent edge transitions from and to the same node. I understand that there are some disadvantages of this project, such as the inability to make from_node_id and to_node_id a composite primary key, and possibly many more.
Currently, I am inclined to make the actual record in the center of the node and create checks for that node in the appropriate database methods. What is the best way to make this project?
source
share