Trees Company: Modeling Hierarchies in the Database

thebruce

Hierarchies and Trees are extremely useful data models. You can find them in everything from course management to inventory management to organizational systems. In Drupal we see these models quite readily in the menu system and the comments system as well as contrib modules.

However, though a hierarchical data model might be conceptually correct it can be difficult to bend the will of the relational (or nearly relational) database to this approach. Unfortunately this too often leads to forcing non-relational and non-set based mindsets onto our database to get it to feel right, return results more quickly, or work within our sensible procedural codebase.

In this session we will:

  • Take a look at 3 different approachesĀ  to keep our data model relational, normalized and set based.
  • We'll examine the benefits and drawbacks (crud performance and navigation) of
    • the Adjacency model,
    • the Path Enumeration model and
    • the Nested set model.
  • Finally, we'll examine and grade Drupal's use of these methods.

Session Track

Coding and Development

Experience Level

Advanced

Drupal Version