0
0
0ldn0mad2019-04-23 16:47:16
Database design
0ldn0mad, 2019-04-23 16:47:16

How to build a table for building a database of relatives?

Good afternoon Guru!
Please tell me how to correctly build a table (maybe more than one) and identify the rows of the table so that you can build simple queries.
Well, let's say there is a user: Ivanov Ivan Anatolyevich, he can be a son and a father at the same time! So he has a father - Ivanov Anatoly Maksimovich and has a son - Ivanov Matvey Ivanovich. Accordingly, the user Ivanov Anatoly Maksimovich has a son - Ivanov Ivan Anatolyevich and a grandson - Ivanov Matvey Ivanovich. There is only one reinforced concrete rule - a father always has one son.
So I have a dilemma - how to build a table and how to order indexes denoting fathers, grandfathers and grandchildren of the same lineage, so that later I can easily and quickly build queries of this kind: Display all grandchildren of the main users or display all those who are the current father? Or display the great-grandfathers of current users?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vdem, 2019-04-23
@vdem

There is only one reinforced concrete rule - a father always has one son.

Er... I don't get it. Can there be only one son? Or is it meant that the entity "father" implies the existence of an entity "son" referring to this "father"? But what about "daughters", because by your definition "father" would not be "father" if he only has "daughter/daughters" and no "sons". Well, of course, by your own definition, if a "father" has more than one son, he is no longer a "father".

S
sim3x, 2019-04-23
@sim3x

Vlob decision

Human:
  ancestor_female = ForeignKey(Human)
  ancestor_male = ForeignKey(Human)

Solutions that are optimal for different cases
https://en.wikipedia.org/wiki/Tree_traversal
Selections are made in procedures or a series of queries
The only reinforced concrete rule
если всех устраивают их родственники, то лучше не проводить ДНК-исследование для проверки родственности

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question