-1

I have to design an application where users have their family members, with their relationship among them denoted in the app. If I log in as father in my app, I see my son name and relationship denoted below as son. If I log in as son, I should see from his interface my name, below, denoted as father. Each member of family is user and his/her own account.
I am working with Flutter + Node.js + Express +Mongo Stack.
Data I have is a bit tricky. I have family with all members with their unique IDs. Each ID has a corresponding relation attribute. Example

ID relation

1 Self

2 Wife

3 Son

This data represents relation of '2' W.R.T 1 and '3' W.R.T '1'

To store this efficiently, I have created a relationship enummeration like this

  1. ['SELF ', 'SELF]

  2. ['HUSBAND', 'WIFE'],

  3. ['FATHER', 'SON'],

  4. ['MOTHER', 'SON'],

  5. ['FATHER', 'DAUGHTER']

    .......

To denote husband = 2 To denote Wife = -2

I am trying to create a matrix for family.
Suppose I have family of 3, the matrix[id1][id2] would give me the relation i.e. what id2 is to id1.

Example ->

          id1      id2       id3

 id1     1         -2         -3

 id2     2          1         -4

 id3     3          4          1

ID relation

1 Self

2 Wife

3 Son

Now by my data i would have these values id1id1 , id1id2 , id1id3 how i can find other entries such as id2id3

I want help in two respect.

  • How can I find all interrelationship mapping of a family if I only have one element relationship to others.

  • Is the way of storing of relationship with matrix is the optimum way or is there any simpler approach or datastructure one can suggest to me based upon the data I have and the preprocessing I need to do.

1 Answer 1

0

I'm used to using relational data and relational databases.

Assuming that a person can only be a member of one family, I'd create a Person table.

Person
------
Person ID
Family ID
Family Relationship (Father, Mother, Son, Daughter)
...

Where Person ID is the primary key and you have a unique index on (Family ID, Family Relationship). The ellipsis signifies the additional person information, like name and address.

You get the Person ID by the person's name or other identifier. You join the Person table to itself by Family ID to get the entire family.

If a person can be a member of multiple families, then you need a different database structure.

Person
------
Person ID
...

Relationship
------------
Person ID 1
Person ID 2
Family Relationship (Father, Mother, Son, Daughter)

To get the whole family, you do the following.

  • Get the Person ID from the Person table by name or other identifier.
  • Get the relationships for that person.
  • Get the Person ID of the father.
  • Get the relationships for the father.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.