Arif
Arif

Reputation: 13

Creating Relationships with Same Label but Different Properties

My goal is to create dynamic relationships with timestamp stored as property of the relationship. So, 2 nodes may have many relationships with the same label but different property values.

I can achieve that using Cypher by the following:

CREATE 
(s1:Node {name:'s1'}), 
(s2:Node{name:'s2'}), 
(s1)-[r1:CONNECTS_TO{from:456}]->(s2), 
(s1)-[r2:CONNECTS_TO{from:1234}]->(s2)

However, I cannot find the same way to do that using Py2neo. I tried this:

from py2neo import Graph, Node, Relationship

graph = Graph(password='neo4jneo4j')

s1 = Node('Node', name='s1')
s2 = Node('Node', name='s2')

aw = Relationship(s1, 'CONNECTS_TO', s2, from=456)
graph.create(aw)

aw2 = Relationship(s1, 'CONNECTS_TO', s2, from=1234)
graph.create(aw2)

The code above doesn't create two relationships. Instead, the latter one updates the former one.

How can I do it using Py2neo?

Thanks!

Upvotes: 1

Views: 936

Answers (1)

Nigel Small
Nigel Small

Reputation: 4495

This is not possible with the py2neo Node and Relationship objects. You'll have to use Cypher to create multiple similar relationships like this.

Upvotes: 1

Related Questions