Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-18-2020 08:40 PM
I have the following two triggers named 'loadEnrollments' and 'loadDeenrollments'.
CALL apoc.trigger.add('loadEnrollments',
"UNWIND apoc.trigger.nodesByLabel($assignedLabels, 'Enrollment') AS node
MERGE (p1:SPerson { name: node.name, cell: node.cell, created_at: node.created_at})
WITH p1, node
MATCH (n:SPerson)
WITH node, COUNT(n) as size
CALL apoc.do.when(
size>3,
'
MATCH(p1:SPerson),(c:Course)
WHERE p1.name=node.name AND c.name=\"Paradigm Shifting 101\"
CREATE (p1)-[:Waitlist]->(c)
SET p1.status=2
WITH node
RETURN NULL',
'
MATCH(p1:SPerson),(c:Course)
WHERE p1.name=node.name AND c.name=\"Paradigm Shifting 101\"
CREATE (p1)-[:Enrolled]->(c)
SET p1.status=1
WITH node
RETURN NULL', {node:node}) YIELD value
DETACH DELETE node",
{ phase: 'after' })
CALL apoc.trigger.add('loadDeenrollments',
"
UNWIND apoc.trigger.nodesByLabel($assignedLabels, 'Deenrollment') AS node
MATCH (p1:SPerson {name: node.name, cell: node.cell})
MATCH (c:Course {name: 'Paradigm Shifting 101'})
CREATE (p1)-[:Deenrolled]->(c)
SET p1.status=3
WITH p1, node,c
MATCH (p1:SPerson {name: node.name, cell: node.cell})-[r:Enrolled]->(c)
DELETE r
DETACH DELETE node
WITH p1,c
MATCH (p1)-[r:Enrolled]->(c)
WITH COUNT(r) as k
CALL apoc.do.when(
k<3, '
MATCH (p1:SPerson)-[:Waitlist]->(c:Course)
WITH min(p1.created_at) AS min
MATCH (p1:SPerson),(c:Course)
WHERE p1.created_at = min
CREATE (p1)-[:Random]->(c)
RETURN p1,c',
'
MATCH (n:SPerson) RETURN n
',{k:k}
) YIELD value
RETURN NULL",
{ phase: 'after' })
When I load both of them and create a 'Enrollment' nodes by the following commands. The 'loadenrollment' trigger works as desired and create SPerson nodes for cat1,cat2 and cat3 and creates an 'enrolled' relationship with the 'course' node.
CREATE (:Enrollment { name: "cat1", cell: "123", created_at: TIMESTAMP()});
CREATE (:Enrollment { name: "cat2", cell: "123", created_at: TIMESTAMP()});
CREATE (:Enrollment { name: "cat3", cell: "123", created_at: TIMESTAMP()});
The Problem occurs when I create the 4th node
CREATE (:Enrollment { name: "cat4", cell: "123", created_at: TIMESTAMP()});
Ideally, it should create a 'SPerson' node for cat4 and add a 'waitlist' relationship with the 'course' node. But for some reason when I create that node it adds the 'waitlist' relationship but also adds the 'Random' relationship that I defined in the second trigger('loadDeenrollments'). This should never happen as this trigger would only trigger when I create a 'Deenrollment' node but for some reason it is executing that trigger.
Also, I tried adding just the 'loadEnrollments' trigger and it works as desired(obviously, as there is no 'loadDeenrollments' trigger) i.e. creating the four 'SPerson' nodes and with three nodes having 'enrolled' relationship and one having 'waitlist' relationship.
I don't know whats's wrong. Any help is appreciated!
All the sessions of the conference are now available online