OrientDB:在pyorient中为两个顶点类创建边

时间:2018-07-08 02:22:21

标签: python orientdb pyorient

我正在尝试使用pyorient为两个顶点类创建一条边。我这样做的方式是;

vertex_class = client.command( "create class ABC extends V")
vertex_class = client.command( "create class my_class extends V")
edge_class = client.command("CREATE CLASS E12 EXTENDS E")
edge_class = client.command("create edge E12 from ABC to my_class")

已成功创建顶点类和边缘类,但是,我无法创建边缘。关于我在做什么错的任何想法吗?我是否必须先添加顶点(如果是),然后如何在pyorient中添加顶点?

1 个答案:

答案 0 :(得分:0)

错误似乎与python无关。这个问题更多的是OrientDB问题而不是python问题。创建边时,必须指定资源ID,也可以使用内联选择。我使用的是另一个示例,因为您的顶点,边缘和链接不清楚。

CREATE CLASS Customer EXTENDS V
CREATE CLASS Account EXTENDS V
CREATE CLASS Owns EXTENDS E

CREATE VERTEX Customer SET name = 'John'
CREATE VERTEX Account SET accountnum = '12345678910'

#Option 1: You will have to get the rid of the vertices 
# You can use SELECT to get the record ID. 
# SELECT FROM Customer WHERE name = 'John'
# SELECT FROM Account where accountnum = '12345678910'
# Use the RID to create the edge
CREATE EDGE owns FROM #10:0 TO #11:0

#Option 2: You can use select inline which will create all the edges
CREATE EDGE Owns FROM ( SELECT FROM Customer where name = 'John' ) TO ( 
SELECT FROM Account where accountnum = '12345678910' )