Muhammad
Muhammad

Reputation: 305

OrientDB: Creating Edges for two vertex classes in pyorient

I am trying to create an edge for two vertex classes by using pyorient. Th way I am doing it is;

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")

The vertex classes and edge class are created successfully, however, I am unable to create the edge. Any ideas on what I am doing wrong? Do I have to add vertexes first, if yes, then how I can do that in pyorient?

Upvotes: 1

Views: 512

Answers (1)

MichaelR
MichaelR

Reputation: 196

The error is not anything to do with python it seems. This question is more of an OrientDB question than python question. When you create the edge, you have to specify the resource id or you can use inline select. I am using a different example as I am not clear on your vertex, edge and links.

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' )

Upvotes: 1

Related Questions