Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
on 06-19-2019 06:39 AM
Hi there:
I am working on creating a dynamic family tree. I have all "parent-of" relationships in a single direction between parent and child.
Is there a way that I can query in the reverse from child to parent without creating a bi-directional relationship?
Thanks
You should be able to do:
MATCH (parent)-[:PARENT_OF]->(child) RETURN parent, collect(child) as children
OR
MATCH (parent)-[:PARENT_OF]->(child) RETURN child, collect(parent) as parents
depending on if you want the children per parent, or parents per child. You don't need an extra relationship pointing in the opposite direction (parent)<-[:CHILD_OF]-(child)
Hope that helps,
Mike French
Hi Mike,
Thanks for the suggestion, but this is showing me the children related to the parent.
I am seeking the following query.
I have Grand-dad as "parent-of" dad, dad as "parent_of" grandchild relationship, which is unidirectional.
I am seeking a query that given grandchild, how do I reverse query to get back to grand-dad? Do I need to set up a bi-directional relationship such as "child-of"
Thanks Mike, your suggestion works.... Awesome