这是我的问题的后续跟进:
How to implement a many-to-many hierarchical structure in MySQL
和这里:
How to record sequential collections of records in MySQL.
简而言之,我想在MySQL中实现一个食谱表和另一个指令.配方是一系列连续的指令或其他配方.例如,你可以想象一个Peach_preserve配方,一个使用Peach_preserve的Peach_tart,以及一系列其他步骤(指令). Peach_preserve可用于许多其他配方.
recipe
id name
1 Peach preserve
2 Cubed peeled peaches
3 Fresh peaches
4 Powdered sugar
5 Cook together
6 Peel and cut in chunks
7 Mix
step (or instruction)
id desc
1 Cook together
2 Buy peaches
3 Buy sugar
4 Peel and cut in chunks
5 Mix
recipe_instruction
(Ancestor) (Descendant)
recipe_id step_id depth descendant_is_instruction
3 3 0 0
3 2 1 1
4 4 0 0
4 3 1 1
6 6 0 0
6 4 1 1
2 2 0 0
2 3 1 0
2 2 2 1
2 6 1 0
2 4 2 1
(and so on...)
我不是the descendant_is_instruction标志的粉丝,但我不知道怎么做.我想我可以用descendant_is_leaf替换它以识别终端项目……
排序顺序由一个表组成,该表包含深度为1的所有关系:
Depth=1 table
recipe_id step_id order
3 2 1
4 3 1
6 4 1
2 3 1
2 6 2
我在这里简化,因为在实践中我会分离成分和说明,但你明白了.
那么,这是一种结合分层数据结构和步骤顺序概念的好方法吗?我应该做些什么来改进/简化?