Tree structure model in reference data

I want to implement a multi-level tree using kernel data. My main data model has a Plan object.

Plan / | \ Plan Plan Plan / | \ | | \ Plan Plan ... 

A higher-level plan will relate to many sub-planes.

So how do I establish a relationship?

enter image description here

enter image description here

+6
source share
1 answer

I would define

  • the relationship of to-many subplans (or children ) from the Plan object to itself, with the "Delete Rule" set to "Cascade",
  • one-to-one superplan (or parent ) relation from the Plan object to itself, while the “Delete Rule” is set to “Nullify”,
  • and set them as inverse relationships with each other.

If you delete one Plan object, then automatically

  • all subplanes are deleted due to the Cascade deletion rule and
  • the plan is deleted from its parent due to the Nullify deletion rule.
+13
source

Source: https://habr.com/ru/post/945353/


All Articles