Search code examples
phpsymfonytreegenealogy

How to have recursive tree genealogy in symfony


I'm making tree genealogy in symfony.

I have two entities :

User: id    firstname    partner    
       1    Julien       Anne      
       2    Eric         Marie    

Relation: id    family_id    child
          1     1            Manon 
          2     1            Camille
          3     2            Julie

I would like to have recursive tree genealogy like child can have partner and can have children but I don't know how to do that.

Shoud I need an other entity ?

Thank you for your help


Solution

  • You need to think about your data design before you start trying to apply it to a particular programming environment.

    Think about separating (all) People from (all) Relationships.

    Person: Name, Id (and any other demographics you want to store, e.g. date of birth)

    Relationship: Id1, Id2, Relationship Type

    Relationship Type might be Partner, Child.

    Then you can give a child a partner, or a child of their own, without trouble.

    Hope this makes sense.