Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I want to create an apoc trigger that will trigger when a relationship is removed. The trigger needs to find the nodes
m
and
n
that the deleted relationship was connecting. Below is what I have, but
MATCH (m)-[deletedRel]->(n)
does not find any matches. What is the correct way to find the two nodes that were connected by a removed relationship?
CALL apoc.trigger.add('myTrigger',
"UNWIND $deletedRelationships as deletedRel
WITH apoc.trigger.toRelationship(deletedRel, $removedRelationshipProperties) AS deletedRel
WITH deletedRel WHERE apoc.rel.type(deletedRel) = 'MY_REL_TYPE'
MATCH (m)-[deletedRel]->(n)
WITH deletedRel, m, n
CREATE (r:Report {myId: id(deletedRel), type: apoc.rel.type(deletedRel)})" ,
{phase:'before'})
You can try using the startNode
and endNode
functions, like this:
CALL apoc.trigger.add('myTrigger',
"UNWIND $deletedRelationships as deletedRel
WITH apoc.trigger.toRelationship(deletedRel, $removedRelationshipProperties) AS deletedRel
WITH deletedRel WHERE apoc.rel.type(deletedRel) = 'MY_REL_TYPE'
WITH deletedRel, apoc.rel.startNode(deletedRel) AS m, apoc.rel.endNode(deletedRel) AS n
CREATE (r:Report {myId: id(deletedRel), type: apoc.rel.type(deletedRel)})" ,
{phase:'before'})
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.