Search code examples
pythonneo4jneo4jrestclient

create relationships on existing nodes neo4jrestclient


I am trying to use neo4jrestclient and trying to create a relationship on existing node

movie = db.labels.get('Movie')
u1 = db.nodes.create(title="titanic")
movie.add(u1)
person = db.labels.get('person')
person.get(name ='abc').relationships.create("ACTS_IN", u1)

AttributeError: 'Iterable' object has no attribute 'relationships'

Process finished with exit code 1


Solution

  • As far as I can tell from http://neo4j-rest-client.readthedocs.io/en/latest/labels.html, person.get(name = 'abc') is returning a list (or something else that will work like a list).

    If you know there is exactly one person with the name 'abc', you can do

    person.get(name='abc')[0].relationships.create("ACTS_IN",u1)
    

    If there might be more (or possibly zero), something like:

    for p in person.get(name='abc'):
       p.relationships.create("ACTS_IN",u1)
    

    should work