如何防止neo4j中的循环依赖

时间:2018-01-23 12:32:50

标签: neo4j cypher

我是Neo4j的新手并尝试使用它来保存节点之间的某些关系,这会阻止循环循环。

我创建了一个应用程序,当某个节点上发生某种类型的CRUD操作时,用户可以运行某些触发器。在下图中,例如:如果在员工上发生插入,则插入部门。所以我有标签:collection的节点以及它们之间的关系,使用[:collection_rel]和一些属性。

我有一个场景,我需要阻止创建关系,如果创建了这种关系,那么这将导致循环依赖。这用红色显示" x"。因此,如果我们尝试使用属性"OnInsert-ThenInsert""OnUpdate-ThenUpdate"添加位置和员工之间的关系,则会导致无限循环。因此,对于这种情况,我们需要阻止添加关系。

如何实现这一目标?这在Neo4j中是否可行?

示例数据:

CREATE (n:Collection { collection_name: "employee" }), (n1:Collection { collection_name: "department" }), (n2:Collection { collection_name: "category" }), (n3:Collection { collection_name: "location" }) RETURN n,n1,n2,n3

MATCH (a:Collection { collection_name: "employee" }), (b:Collection { collection_name: "department" })
CREATE (a)-[r:collection_rel {type: "CRUD", details: "OnUpdate-ThenUpdate"}]->(b)

MATCH (a:Collection { collection_name: "employee" }), (b:Collection { collection_name: "department"})
CREATE (a)-[r:collection_rel {type: "CRUD", details: "OnDelete-ThenInsert"}]->(b)

MATCH (a:Collection { collection_name: "employee" }), (b:Collection { collection_name: "department" })
CREATE (a)-[r:collection_rel {type: "CRUD", details: "OnInsert-ThenInsert"}]->(b)

MATCH (a:Collection { collection_name: "department" }), (b:Collection { collection_name: "category" })
CREATE (a)-[r:collection_rel {type: "CRUD", details: "OnUpdate-ThenUpdate"}]->(b)

MATCH (a:Collection { collection_name: "department" }), (b:Collection { collection_name: "location" })
CREATE (a)-[r:collection_rel {type: "CRUD", details: "OnInsert-ThenInsert"}]->(b)

MATCH (a:Collection { collection_name: "category" }), (b:Collection { collection_name: "location" })
CREATE (a)-[r:collection_rel {type: "CRUD", details: "OnUpdate-ThenUpdate"}]->(b)

nodes

0 个答案:

没有答案