Use UNWIND alter Receive this question Relationship with id has been deleted in this transaction,Is there any good solution for this problem?

i have those data

create (p:Person{vid:"a"})<-[:Merged{ts:1}]-(:Person{vid:"b"})-[:AlongWith{count:1,ts:1}]->(:Person{vid:"c"})-[:Merged{ts:1}]->(:Person{vid:"d"})


i run this

				 UNWIND [{OriginPersonID:"c",MergedPersonID:"d"},{OriginPersonID:"b",MergedPersonID:"a"}] as merge 
				MATCH (originPerson:Person{vid:merge.OriginPersonID})
				MATCH (mergedPerson:Person{vid:merge.MergedPersonID})
				OPTIONAL MATCH (originPerson)-[r:AlongWith]-(pend:Person{}) where pend<>mergedPerson
				FOREACH(ignoreMe IN CASE WHEN r IS NOT NULL  THEN [1] ELSE [] END |
				  	MERGE (mergedPerson)-[r2:AlongWith]-(pend)
						ON CREATE SET r2.count = r.count, r2.lastTs = r.lastTs
						ON MATCH SET r2.count = r.count + r2.count, r2.lastTs = apoc.coll.max([r.lastTs, r2.lastTs])
					DELETE r

				)

				with originPerson,mergedPerson,merge
				OPTIONAL MATCH (originPerson)-[r3]-(end:Person) where end.vid=merge.MergedPersonID or end.vid=merge.OriginPersonID
				Delete r3
				Delete originPerson

Receive this question
image

Is there any good solution for this problem?

But I can successfully run the split in a transaction

UNWIND [{OriginPersonID:"c",MergedPersonID:"d"}] as merge 
				MATCH (originPerson:Person{vid:merge.OriginPersonID})
				MATCH (mergedPerson:Person{vid:merge.MergedPersonID})
				OPTIONAL MATCH (originPerson)-[r:AlongWith]-(pend:Person{}) where pend<>mergedPerson
				FOREACH(ignoreMe IN CASE WHEN r IS NOT NULL  THEN [1] ELSE [] END |
				  	merge (mergedPerson)-[r2:AlongWith]-(pend)
						ON CREATE SET r2.count = r.count, r2.lastTs = r.lastTs
						ON MATCH SET r2.count = r.count + r2.count, r2.lastTs = apoc.coll.max([r.lastTs, r2.lastTs])
					DELETE r

				)
				with originPerson,mergedPerson,merge
				OPTIONAL MATCH (originPerson)-[r3]-(end:Person) where end.vid=merge.MergedPersonID or end.vid=merge.OriginPersonID
				Delete r3
				Delete originPerson

UNWIND [{OriginPersonID:"b",MergedPersonID:"a"}] as merge 
				MATCH (originPerson:Person{vid:merge.OriginPersonID})
				MATCH (mergedPerson:Person{vid:merge.MergedPersonID})
				OPTIONAL MATCH (originPerson)-[r:AlongWith]-(pend:Person{}) where pend<>mergedPerson
				FOREACH(ignoreMe IN CASE WHEN r IS NOT NULL  THEN [1] ELSE [] END |
				  	merge (mergedPerson)-[r2:AlongWith]-(pend)
						ON CREATE SET r2.count = r.count, r2.lastTs = r.lastTs
						ON MATCH SET r2.count = r.count + r2.count, r2.lastTs = apoc.coll.max([r.lastTs, r2.lastTs])
					DELETE r

				)
				with originPerson,mergedPerson,merge
				OPTIONAL MATCH (originPerson)-[r3]-(end:Person) where end.vid=merge.MergedPersonID or end.vid=merge.OriginPersonID
				Delete r3
				Delete originPerson

use sub query can solution

				UNWIND [{OriginPersonID:"b",MergedPersonID:"a"},{OriginPersonID:"c",MergedPersonID:"d"}] as merge 
				call {
					with merge
				MATCH (originPerson:Person{vid:merge.OriginPersonID})
				MATCH (mergedPerson:Person{vid:merge.MergedPersonID})
				OPTIONAL MATCH (originPerson)-[r:AlongWith]-(pend:Person{}) where pend<>mergedPerson
				FOREACH(ignoreMe IN CASE WHEN r IS NOT NULL  THEN [1] ELSE [] END |
				  	merge (mergedPerson)-[r2:AlongWith]-(pend)
						ON CREATE SET r2.count = r.count, r2.lastTs = r.lastTs
						ON MATCH SET r2.count = r.count + r2.count, r2.lastTs = apoc.coll.max([r.lastTs, r2.lastTs])
					// return r
					// DELETE r

				)
				delete r
				// return r,originPerson,pend
				with originPerson,mergedPerson,merge
				OPTIONAL MATCH (originPerson)-[r3]-(end:Person) where end.vid=merge.MergedPersonID or end.vid=merge.OriginPersonID
				Delete r3
				Delete originPerson}