I have a hierarchy of categories that I want to query using cypher - one query which will return the list of item, with the relationships between them as sub lists.
I am creating my items like this:
CREATE (C1:Category {name:"Sport"})
CREATE (C1A:Category {name:"NHL"})
CREATE (C1B:Category {name:"NBA"})
CREATE (C1C:Category {name:"NFL"})
CREATE (C1)-[:SUB_CATEGORY]->(C1A)
CREATE (C1)-[:SUB_CATEGORY]->(C1B)
CREATE (C1)-[:SUB_CATEGORY]->(C1C)
CREATE (C2:Category {name:"Music"})
CREATE (C2A:Category {name:"Rock"})
CREATE (C2B:Category {name:"Pop"})
CREATE (C2C:Category {name:"Classic"})
CREATE (C2)-[:SUB_CATEGORY]->(C2A)
CREATE (C2)-[:SUB_CATEGORY]->(C2B)
CREATE (C2)-[:SUB_CATEGORY]->(C2C)
I want the query to return something like:
{categories:[{name:music,id:1,categories:[{name:rock,id:2},{name:pop,id:3}]]...{name:sport,id:10,categories:[{name:nhl...}
which I can use to populate drop downs for selecting a category / sub category. (I want to query the entire tree in one query and not one by one at this point)
Another question (for cases where I would like to query partial parts of the tree):
How can get all the main categories (ones who are NOT sub categories of another category...)