简体   繁体   English

为取决于方向的Neo4j关系声明唯一约束(理想情况下为py2neo)

[英]Declare a unique constraint for Neo4j relationships dependent on direction (ideally with py2neo)

Is there an alternative to py2neo's create_unique method for relationships that takes direction into account? py2neo的create_unique方法是否有替代方法,可以考虑方向? Such that uniqueness === same nodes, same label, and same direction? 这样的唯一性===相同的节点,相同的标签和相同的方向?

A solution for Py2neo would be ideal, but I wouldn't be opposed to switching to a more complete driver if there is one. Py2neo的解决方案将是理想的选择,但是如果有的话,我不会反对切换到更完整的驱动程序。

EDIT : seems like it's a functionality that doesn't exist in Cypher in the first place. 编辑 :似乎它是Cypher最初不存在的功能。 I still think it would make a useful driver functionality. 我仍然认为这将使驱动程序功能有用。

EDIT 2 : Cypher let's me use create_unique with direction: 编辑2 :Cypher让我在方向上使用create_unique:

MATCH (b { name: 'Bob' }), (a {name:'Alice'})
CREATE UNIQUE (b)-[r:SWIPED_RIGHT]->(a)
RETURN r

Would be lovely to be able to do the same without writing a raw cypher query. 如果不编写原始密码查询就能够执行相同操作,那将非常可爱。

By default in Py2neo all relationship are created "Outgoing". 默认情况下,在Py2neo中,所有关系都创建为“传出”。 Use " http://py2neo.org/2.0/essentials.html#py2neo.Rev " for "Incoming" relationships. 将“ http://py2neo.org/2.0/essentials.html#py2neo.Rev ”用于“传入”关系。

Example: - //Creates "Outgoing" Relationship Relationship(Node("FEMALE",name="A"),"FRIEND",Node("FEMALE",name="B")) 示例:-//创建“传出”关系Relationship(Node(“ FEMALE”,name =“ A”),“ FRIEND”,Node(“ FEMALE”,name =“ B”))

//Creates "Incoming" Relationship Relationship(Node("FEMALE",name="A"),Rev("FRIEND"),Node("FEMALE",name="B")) //创建“传入”关系Relation(Node(“ FEMALE”,name =“ A”),Rev(“ FRIEND”),Node(“ FEMALE”,name =“ B”))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM