It is necessary in the database to store two identical in tree structure. Each tree in the final leaves has a set of attributes (for each tree its own set). Horizontal links can be established between the nodes of these two trees.
The question is - trees should be stored in different tables.
- Tree1
- id
- owner_id
- name
- is_leaf
- Tree1LeafAttributes
- leaf_id (primary)
- tree1_attr1
- tree1_attr2
- ...............
- Tree2
- id
- owner_id
- name
- is_leaf
- Tree2LeafAttributes
- leaf_id (primary)
- tree2_attr1
- tree2_attr2
- ...............
- Links
- tree1_node
- tree2_node
Or both trees stored in the same table?
- Trees
- id
- owner_id
- name
- tree_type
- is_leaf
- Tree1LeafAttributes
- leaf_id (primary)
- tree1_attr1
- tree1_attr2
- ...............
- Tree2LeafAttributes
- leaf_id (primary)
- tree2_attr1
- tree2_attr2
- ...............
- Links
- tree1_node
- tree2_node
Pros of the first option: an order of magnitude easier to validate. You can not link to the wrong tree
Advantages of the second - no duplication of structure