Search code examples
pythonneo4jpy2neo

How to use graph.merge() py2neo v3 to replace graph.merge_one() in Nicole White's blog app


I am trying to recreate Nicole White's microblog application powered by Flask and Neo4j tutorial but using py2neo v3 rather than v2. I'm a novice but keen to understand & learn by tinkering...

I know that graph.merge_one() has been replaced by graph.merge() in v3 but I cannot figure out how to get tags out of my database, or if they don't exist then create them in order to use them to create a relationship with a node.

Nicole does it like this using py2neo v2...

for tag in tags:
        t=graph.merge_one("Tag", "name", tag)
        rel=Relationship(t, "TAGGED", post)
        graph.create(rel)

How can I do it using graph.merge() from py2neo v3?


Solution

  • This appears to work but...

    for tag in tags:
            t = Node("Tag", name=tag)
            graph.merge(t)
            rel=Relationship(t, "TAGGED", post)
            graph.create(rel)
    

    I wish there was a tutorial to follow. The docs are so terse...