cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Outward relationship display for a family tree

Hi,
I created a simple family tree with my parents, siblings, wife and kids. It has bi directional relationships and I'm able to retrieve the family tree. But the ask is, If I run a cipher against my wife, I need all outward relationships. Is there a way to do it? Any help would be greatly appreciated.

Jason

2 REPLIES 2

Hi Jason,

I made my sample family tree.
The family tree is a two-way relationship, but I think it's better in one direction.

For example.
You can use either [:PARENT_OF] or [CHILD_OF].
The same is true for [:MARRIED_TO].

It is bidirectional in the following cases.
(dad)-[:LIKES]->(mom)
(mom)-[:LIKES]->(dad)

2X_0_08002bdf8a520b9ddee64f17d2d1f44e053394a7.jpeg

Sample Cypher

CREATE (father1:Person {name: 'Father'})-[:MARRIED_TO]->(mother1:Person {name: 'Mother'}),
       (father2:Person {name: 'Father'})-[:MARRIED_TO]->(mother2:Person {name: 'Mother'}),
       (dad:Person {name: 'Dad'})-[:MARRIED_TO]->(mom:Person {name: 'Mom'}),
       (brother:Person {name: 'Brother'}),
       (son:Person {name: 'Son'}),
       (daughter:Person {name: 'Daughter'}),
       (father1)-[:FATHER_OF]->(dad),
       (mother1)-[:MOTHER_OF]->(dad),
       (father2)-[:FATHER_OF]->(mom),
       (mother2)-[:MOTHER_OF]->(mom),
       (dad)-[:FATHER_OF]->(son),
       (mom)-[:MOTHER_OF]->(son),
       (dad)-[:FATHER_OF]->(daughter),
       (mom)-[:MOTHER_OF]->(daughter),
       (dad)-[:BROTHER_OF]->(brother)

You don't need an arrow to find your partner.

MATCH (:Person {name: 'Dad'})-[:MARRIED_TO]-(who:Person)
RETURN who.name

who.name
"Mom"

If you are looking for children, you will need an arrow.

MATCH (:Person {name: 'Dad'})-[:FATHER_OF]->(who:Person)
RETURN who.name

who.name
"Son"
"Daughter"

If you want to find parents, you need an arrow.

MATCH (:Person {name: 'Dad'})<-[:FATHER_OF|MOTHER_OF]-(who:Person)
RETURN who.name

who.name
"Mother"
"Father"

This may not be the answer you're looking for, but I hope it's helpful.

What do I return to get a graph output like yours?