I'm looking for opinions on how to model a directed graph that contains one special node.
Special node:
Current design:
Tables: Nodes, Edges. Edges contains two columns; from_node_id and to_node_id, each referencing a record in the Nodes table.
Rather than storing the special node as the first record in the Nodes table, I decided not to keep a record for it at all, constructing it separately from any database queries. In the Edges table, NULL takes on a special meaning in from_node_id column, referring to the center node.
My motivation for using this design was that I wouldn't have to worry about protecting a center node record from deletion/modification or being referenced in the to_node_id column of the Edges table. This would also automatically prevent an edge from going from and to the same node. I realize there are some drawbacks to this design, such as not being able to make from_node_id and to_node_id a composite primary key, and probably many more.
I'm currently leaning towards making the center node an actual record and creating checks for that node in the relevant database methods. What's the best way to go about this design?
I see some arguments against using NULL in this case.
In other words I would prefer to have row in the database for the central node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With