简体   繁体   中英

How to model a recursive optional Dependency in mySQL?

How do I go about modelling recursive optional dependency? Like a product may be comprised of other products? but can also be sold alone. I'd like to be able query a chimeric product from the top down ie from the parent to children as opposed to querying children who have the same parents, which is what my current design solution does.

You need the bill of materials pattern for this type of requirement. The comment by Neville K points to a good blog about bill of materials.

In order to make it easier to work with the unlevel tree structure that such a design involves, you can use a physical implementation technique called visitation numbers , which I describe in some detail in my answer to this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM