This is something that keeps coming up on different projects, so I’d like to share how I usually do this. There are some examples out there which try to describe a very generic solution which can be used in almost any case. However, such solutions very quickly become very complex. To keep things simple, I have tried to keep this example fairly specific but adaptable to a wide range of circumstances. Specifically this example is using a fixed hierarchy structure with a fixed number of levels, each of which will be represented by a different table.
If you have not read these posts yet, I recommend you do that first, to help with the understanding of this post, which explains how to provide a more useful tree reference in the calling form.