0

I am using GraphObject to map Neo4j nodes to Python Classes, I like when I get a Node with relationships because I get its nodes too as Python Classes. For example, if my class is Person, I can use Person.select, and get Person objects.

Now, I need to execute a complex query so that It needs to call a spatial procedure, I can only do this with graph.run("MY_COMPLEX_QUERY"), but this returns nodes (and these nodes don't have relationships).

Is it posible to execute any query with GraphObject selector with a single query? Any ideas?

Thanks!!, Regards

PD: I can get all ids, and after use Person.select by id, but it isn't good solution.

  • If you can construct your query in terms of a predicate expression (`WHERE `) then you can use `Person.select(*args).where("")` to append predicates to that specialized select query. But you really shouldn't rely on the `py2neo` OGM to do any level of complex work, it utilizes only a very small subset of Cypher. – Tore Eschliman Oct 10 '16 at 19:08
  • Hi, I can't, I need to call spatial procedure. Thanks I think to create a static method that it transforms node Neo4j to Json, and so I only use one query (but I need to keep two similar methods by class...). Any more solution? Thanks!! – David González Oct 11 '16 at 07:08

1 Answers1

0

You can't do it all in one query. Behind the scenes, py2neo doesn't even appear to do all of its work in one query. If you really want to get GraphObjects, you can do it from a list of nodes like so:

def make_GraphObjects(graph, GraphObjectCls, nodes):
    for node in nodes:
        obj = GraphObjectCls.wrap(node)
        graph.pull(obj)
        yield obj

That will be more than one transaction, but that's the limit of using the OGM. It claims to simplify your interactions, but I find it mostly just limits them.

Tore Eschliman
  • 2,477
  • 10
  • 16