I want to create tree-view for display or show family member's relation. For this I created 3 tables i.e following.

relations -> [r_id,relation] .....//e.g father,mother,son,etc.
familyRelations ->[fr_id,fk_f_id1,fk_r_id,fk_f_id2]      //to show A is Father OF b.

Here problem is, if I say A is father OF B and C than it'll make one entry in familyRelations table. But here it will also create one more entry for B is daughter of A. So in opposite relation (e.g father->son or son->father, etc ) it'll create entry for all case.

So if there are N no of people in family then it'll create N * N entries in familyRelations table.

How to define relationship with other members. This flow is right or need to change? I am confused in this.

So how to solve this problem. Or is there any another way?

  • how many relations are in the relations table?
    – DFord
    Jul 29 '14 at 11:47
  • If you want to use family tree as the model for your objects, you won't need N*N entries in the familyRelations table because you should only care about relations between a pair of objects at 2 adjacent depths. Other relations can be inferred from the path you need to get from one node to another.
    – InformedA
    Jul 29 '14 at 11:50
  • @DFord : more than 10
    – Kreya
    Jul 29 '14 at 12:38
  • @randomA :Can you please explain it lil bit more ? ? ?
    – Kreya
    Jul 29 '14 at 12:41
  • im not sure if this is what @randomA meant, but if you just insert the parents and possibly children of the for each record in the familyDetails table, from that you can figure out all the other relations.
    – DFord
    Jul 29 '14 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.