MySQL Store Relationship (Family) Tree

柔情痞子 提交于 2019-11-30 10:09:18

An idea that comes from the Geneapro schema and RootsMagic.

person
------
person_id
name (etc)

life_event_types
----------------
life_event_type_id
life_event_type_description (divorce, marriage, birth, death)

life_events
-----------
life_event_id
life_event_type_id
life_event_description
life_event_date

life_event_roles
----------------
life_event_role_id
life_event_role (mother, father, child)

person_event_role
-----------------
person_id - who
life_event_id - what happened
life_event_role_id - what this person did

So you could have a life event of type "birth", and the role_id tells you who were the parents, and who was the child. This can be extended to marriages, deaths, divorces, foster parents, surrogate parents (where you might have 3 or 4 parents with a very complicated relationship), etc.

As for storing more distant relationships, you can calculate these. For example, you can calculate the Father of anybody by getting the person who has the 'father' role with a matching event_id. You can then get the father of that person, and you have the grandfather of the original person. Anywhere that somebody is unknown, create the person with unknown data.

person
-------
person_id
other_stuff

relation
----------
person_id_1
person_id_2
relationship_type
begin_dt
end_dt

just populate the relationship type with any value you are interested in. (FK to some picklist would be great)

I put the dates on for an interesting subdiscussion/thought provokation.

John Slegers

The GEDCOM data model and the Gramps data model are two of the most popular formats for exchanging geneological data between different tools. Using either of these data models should both (1) make your tool more compatible with other tools and (2) ensure that your data model is compabible with many special cases, considering both data models are specially designed to deal with geneological data.

Tools like Oxy-Gen or the Gramps PHP exporter should get you on your way with respect to how to import GEDCOM data into a database.

For more details, see also my answer to “Family Tree” Data Structure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!