priya
priya

Reputation: 26719

How to model family relationships using Neo4j

We are trying to model family relationships using neo4j and would like to understand the best way to model this. Note: We already have users (e.g. id, name) residing in a MySQL database.

We have the following sample data (John Davis married to Nancy ad have 2 children Joshua and Susan). Would it be possible to have a single relationship between husband and the wife node and have a bi-directional interpretation.

e.g. John Davis "husband of" Nancy, Nancy "wife of" John Davis.

OR

John Davis "husband-wife-relationship" Nancy So if someone tried to read the node "John Davis" and tries to lookup family information, it should know the John is "husband of" Nancy and would read the other way for Nancy, which is Nancy is "wife of" John.

What would be the correct way to model this, given that user information is already stored as part of a MySQL database.

Upvotes: 1

Views: 674

Answers (1)

Mattias Finné
Mattias Finné

Reputation: 3054

It should be enough with a MARRIED_TO relationship. If we talking strictly man-women marriages we could just say that such a relationship goes from a man to a women so that an outgoing MARRIED_TO relationship logically means "husband of" and incoming means "wife of". If you're modelling man-man and women-women marriages too then the sex could be encoded as a property on each person node and the combination of that relationship and the property of the start or end node would tell you what it means.

But how you need to model it often depends on how you're planning to query it.

Upvotes: 2

Related Questions