A
A
Andrey Boychenko2018-06-19 14:10:58
Database design
Andrey Boychenko, 2018-06-19 14:10:58

Multilevel database nesting?

Good afternoon everyone! Please tell me in which direction to dig in order to most effectively implement the scheme with a referral. 20 nesting levels.
It looks like this:

Андрей
  (LVL1) Дмитрий
  (LVL2)	(LVL1) Максим
  (LVL3)			(LVL1) Валентин
  (LVL4)					(LVL1) Олег

Let's say Dmitry signed up using Andrey's link. He becomes the first user invited by Andrey. And he has LVL1, therefore he gets N bonuses.
Further on Dmitry's link, Maxim was registered. For Dmitry, he brings N bonuses, like Dmitry for Andrey. But for Andrey, he has LVL2 and receives N-1 bonuses.
What is the principle of such nesting? Thanks for your advice!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Nemiro, 2018-06-19
@Ka4_Piton

Add a link to the parent user ( parent_id ).
And in order to have quick access to the entire chain and not be perverted, you can make an additional field in which to register this very chain. For the user Maxim ref_chain = Andrey/Dmitry . Add triggers to the table to check for chain updates. When accruing bonuses, you can split the ref_chain and accrue to each depending on the level (index). If there are a lot of requests, then you can make a separate table in which the links will be written explicitly for each user (to avoid dynamic building of links):

Андрей  | level 0 | null
Дмитрий | level 1 | Андрей
Максим  | level 1 | Дмитрий
Максим  | level 2 | Андрей

A
Alexander Putrov, 2018-06-19
@Zlobnost

You need to dig towards data storage. To store such a structure, one table and two tables and a table with views and anything else are suitable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question