假设我们有两个节点,User和Post。关系,比如upvote,可以存在为(:User)-[upvote]->;(:Post)
如果以下查询结果为非空列表,则我希望删除该关系:
rel_list = list(graph.match(start_node=user, end_node=post, rel_type="UPVOTED")
if len(rel_list) > 0:
# delete the relationship from the graph
else:
# create the relationship
rel = Relationship(user, "UPVOTED", post)
graph.create_unique(rel)
要删除关系,应该使用
separate
方法:http://py2neo.org/v3/database.html#py2neo.database.Transaction.separate。在您可能需要在GitHub中查看这个问题,以便对此进行一些讨论:https://github.com/nigelsmall/py2neo/issues/508
谨致问候
回答我自己的问题,希望这对其他人也有帮助。在
如果最后出现TypeError(就像在我的例子中一样),那么您获取的rel\uid可能是unicode样式。在这种情况下传递int(rel_id)。在
相关问题 更多 >
编程相关推荐