clement
clement

Reputation: 489

set propery depending on a condition in a cypher request

I'm working on a cypher request but I do not understand how I can set a property depending on a condition. My current request is like the following :

"MATCH (p:Picto{uuid : {pictoUuid}}) OPTIONAL MATCH (p)-[:PICTO_OF]->(e:Element) SET p.deleted = true, e.deleted = true"

What I want to do is set "e.deleted=true" only if all picto of an element have deleted property equals to true.

I think there is something to do like in this post but I do not understand how to achieve that.

Thanks a lot

Upvotes: 0

Views: 71

Answers (1)

cybersam
cybersam

Reputation: 67044

Does this query work for you? It marks the specified Picto as deleted, and then checks if all the Pictos associated with its Element (if any) have been marked deleted. If so, it then marks that Element deleted as well.

MATCH (p:Picto{uuid : {pictoUuid}})
OPTIONAL MATCH (p)-[:PICTO_OF]->(e:Element)
SET p.deleted = TRUE
WITH e
MATCH (x)-[:PICTO_OF]->(e)
WITH e, COLLECT(x) AS pictos
WHERE ALL(p IN pictos WHERE p.deleted = TRUE)
SET e.deleted = TRUE;

Upvotes: 1

Related Questions