Amir Abdollahi
Amir Abdollahi

Reputation: 455

related node to existing node py2neo ogm

I use py2neo V3 to connect neo4j database

my ogm model :

class User(GraphObject):
    __primarykey__ = "username"

    username = Property()
    password = Property()

    ppi_graph = RelatedTo(Graph, "PPI_Graph")

class Graph(GraphObject):
    __primarykey__ = "name"

    name = Property()
    date = Property()

    node = RelatedTo(Node)
    user = RelatedFrom(User,"PPI_Graph")

class Node(GraphObject):
    __primarykey__ = "name"

    name = Property()

    ppigraph = RelatedFrom(Graph, "HAVE_NODE")
    related = Related(Node, "Related")

first method :

find user, create new graph, add user to graph graph.user.add()

graph #connection to neo4j db
user = User.select(graph, username).first()
gr = Graph()
gr.name = "graph"
gr.date = "today"
gr.user.add(user)
graph.push(gr)

this method push data to database

second method:

find user, create new graph, add graph to user user.graph.add()

graph #connection to neo4j db
user = User.select(graph, username).first()
gr = Graph()
gr.name = "graph"
gr.date = "today"
user.ppi_graph.add(us)
graph.push(us)

this method raise error when add ppi_graph to user:

    related_object = self.related_class.wrap(node)
AttributeError: type object 'Graph' has no attribute 'wrap'

why I can not add new graph to finded user ?

Upvotes: 0

Views: 240

Answers (1)

Nigel Small
Nigel Small

Reputation: 4495

Graph and Node are core py2neo classes, you probably shouldn't use those names to define your own classes, lest this kind of confusion arises.

Upvotes: 1

Related Questions