D
D
DieZz2015-07-29 19:52:17
MySQL
DieZz, 2015-07-29 19:52:17

How to store a tree in a database?

I'm trying to figure out how to organize the storage of connections between crosses and couplings. Link is an optical cable that can link:

  • cross-cross
  • cross coupling
  • coupling-coupling

In a simplified form, it looks something like this:
41a7cbf02a544862be1552cdb5920ec2.png
For me, the problem is that the connection can be either with a cross or with a clutch. Now I see the following implementation:
3316ef93578140359cd77efb6e089354.png
I would like to hear opinions on a more competent implementation of the database

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Ivanov, 2015-07-29
@Writerim

objects
id | name | ident
1 | Муфта | mufta
...


links
id_object | id_child

In the objects table, we store the types of objects
. In the links table, links.
You can complicate things by adding such an entity to links as "scheme" or some sort of group specifier.
Variations can be made for a specific case

R
Rsa97, 2015-07-29
@Rsa97

Is there a one-to-one relationship between the `cables` and `communications` tables? Then it is better to combine them into one table.
And it is not clear, in your system, the cable can still connect the cross with the cross or is it always only the cross with a clutch?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question