Unable to create relation with FOREACH clause

According to the documentation: within the FOREACH parentheses, you can do any of the updating commands — SET , REMOVE , CREATE , MERGE , DELETE , and FOREACH. So in your case, I don't see how you can use it since you need to match both nodes.

The best solution is this one:

MATCH (c:Car {carID: car_ID})-[:takePlace]->(e:Event)
WITH e
ORDER BY e.start_time
WITH collect(e) AS events
UNWIND RANGE(0, size(events)-2) AS i
MATCH (a:Event {eventID: events[i].eventID})
MATCH (b:Event {eventID: events[i+1].eventID})
CREATE (a)-[:NEXT]->(b)
1 Like