我使用py2neo V3连接neo4j数据库
我的ogm模型:
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")
第一种方法:
查找用户,创建新图表,将用户添加到图表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)
此方法将数据推送到数据库
第二种方法:
查找用户,创建新图表,向用户添加图表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)
此方法在向用户添加ppi_graph时出现错误:
related_object = self.related_class.wrap(node)
AttributeError: type object 'Graph' has no attribute 'wrap'
为什么我无法向有资格的用户添加新图表?
答案 0 :(得分:1)
Graph
和Node
是核心py2neo类,您可能不应该使用这些名称来定义自己的类,以免产生这种混淆。