Hi,
So I created nodes with
create (n:AssessmentId{AssessmentId:10})
create (m:Questions{Question:"Question1"})
create (o:Questions{Question:"Question2"})
create (p:Questions{Question:"End"})
merge (n)-[:inquire]->(m)
merge (o)<-[:response{Response:"Yes"}]-(m)-[:response{Response:"No"}]->(o)
merge (p)<-[:response{Response:"Yes"}]-(o)-[:response{Response:"No"}]->(p)
return n,m,o,p
When I try to fetch all the Question nodes connected to Assessment Node with their relationships between nodes, the relationships I get is not right. The query I used is
match (n:AssessmentId)-[q:inquire|response*]->(m:Questions)
where n.AssessmentId=10
UNWIND q as rel
return m.Question as Question, COLLECT(DISTINCT rel.Response) as Responses
The output I get is like
But this ain't right as Question1 and Question2 has relationship but End doesn't so the end should have empty box.
How do I fix this? Thanks in advance.
Your approach is not associating the question with its relationships. Try this:
match (n:AssessmentId)-[:inquire|response*]->(m:Questions)
where n.AssessmentId=10
with distinct m as question
return question.Question as Question, [(question)-[r:response]->()|r.Response] as Responses
1 Like
Hie, thank you for your response I didn't know we could do something like that. Well I slightly modified the query to fetch multiple properties from Response
match (n:AssessmentId)-[:inquire|response*]->(m:Questions)
where n.AssessmentId=10
with distinct m as question
return question.Question as Question, [(question)-[r:response]->()|{Response: r.Response, ResponseId: r.ResponseId}] as Responses
Here ResponseId is an integer value and I am trying to sort with ResponseId, but it's not working. Is there a way we could do it? I tried "order by Responses" and also "order by Responses[0].ResponseId" both are not giving me expected answers.