I have a following part of Cypher query:
MATCH (ch:Characteristic) WHERE id(ch) = {characteristicId} WITH ch OPTIONAL MATCH (ch)<-[:SET_ON]-(v:Value)...
first of all I'm looking for (ch:Characteristic) by characteristicId and then applying required logic for this variable at the rest of my query.
my Characteristic can also have(or not) a child Characteristic nodes, like:
(ch:Characteristic)-[:CONTAINS]->(childCh)
Please help to extend my query in order to collect ch and childCh into a list of Characteristic thus I'll be able at the rest of my query to apply required logic to all Characteristic at this list.
UPDATED - possible solution #2
This is my current working query:
MATCH (chparent:Characteristic) 
WHERE id(chparent) = {characteristicId} 
OPTIONAL MATCH (chparent)-[:CONTAINS*]->(chchild:Characteristic) 
WITH chparent, collect(distinct(chchild)) as childs 
WITH childs + chparent as nodes 
UNWIND nodes as ch 
OPTIONAL MATCH (ch)<-[:SET_ON]-(v:Value)-[:SET_FOR]->(Decision) 
OPTIONAL MATCH (v)-[:CONTAINS]->(vE) OPTIONAL MATCH (vE)-[:CONTAINS]->(vEE) 
OPTIONAL MATCH (ch)-[:CONTAINS]->(cho:CharacteristicOption) 
OPTIONAL MATCH (cho)-[:CONTAINS]->(choE) OPTIONAL MATCH (ch)-[:CONTAINS]->(chE) 
DETACH DELETE choE, cho, ch, vEE, vE, v, chE
This is an attempt to simplify the query above:
MATCH (ch:Characteristic) 
WHERE (:Characteristic {id: {characteristicId}})-[:CONTAINS*]->(ch) 
OPTIONAL MATCH (ch)<-[:SET_ON]-(v:Value)-[:SET_FOR]->(Decision) 
OPTIONAL MATCH (v)-[:CONTAINS]->(vE) 
OPTIONAL MATCH (vE)-[:CONTAINS]->(vEE) 
OPTIONAL MATCH (ch)-[:CONTAINS]->(cho:CharacteristicOption) 
OPTIONAL MATCH (cho)-[:CONTAINS]->(choE) 
OPTIONAL MATCH (ch)-[:CONTAINS]->(chE) 
DETACH DELETE choE, cho, ch, vEE, vE, v, chE
but this query doesn't delete required Characteristic nodes and my tests fail. What am I doing wrong at the last query ?