DB modeling for "multilevel marketing"

1

Personal speech,

I'm working on an app that consists of people referencing, just like so-called multilevel marketing.

The general idea is to:

Person A indicates person B (LEVEL 1) if person B indicates person C (person N1 of person B and person N2 of person A) and so on up to N5.

How can I plan this type of table?

NOTE: It will need to be in a postgresql DBMS, as it will be an addition to an existing system

I'm open to any suggestions

    
asked by anonymous 10.11.2016 / 16:51

1 answer

1

Make a table that has an FK for itself. So you use recursion to describe the hierarchical structure of statements. Example:

CREATE TABLE pessoas (
  id serial PRIMARY KEY,
  indicador integer REFERENCES pessoas(id) ON DELETE CASCADE
  -- Demais campos
);
    
10.11.2016 / 17:18