Search code examples
pythonneo4jpy2neo

how to use graph.pull in py2neo?


in my code, i use py2neo to create objects with the label foobar. If i want to pull some of them out of the database, it returns:

None

code (note that there are already foobar objects in the DB):

class foobar(GraphObject):
    __primarykey__ = "name"

    name = Property()

#... graph initialized etc.

foo = foobar()
foo.name = "bar"
foo = graph.pull(foo) #get all foobar data from graph
print(foo)

None


Solution

  • From the doc:

    Graph.pull(graph_object): Update a GraphObject and its associated RelatedObject instances with changes from the graph.

    So if you want to get the data from the graph, maybe you should create or push your object to graph first? And if you want to retrieve existing object you have to select it first

    foobar.select(graph).where("_.name = 'bar'").first()
    

    http://py2neo.org/v3/ogm.html#object-selection