1

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?

Muhammad
  • 305
  • 2
  • 6
  • 20

1 Answers1

1

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' )
MichaelR
  • 196
  • 1
  • 14
  • Thanks. Do you first have to create vertex classes Customer and Account first before creating their vertices? Also, same for edge? How to get the rid of vertices and edges? Why "create edge E12 from ABC to my_class" did not work in my case? – Muhammad Jul 08 '18 at 08:57
  • That's correct. First you will be creating the vertex class. Otherwise it will create in the base class V. I will edit to add those as well just to be clear. – MichaelR Jul 08 '18 at 14:09
  • OK, and will I have to create the links after creating the edge class? e.g. client.command("create property Own.out LINK Customer") client.command("create property Own.in LINK Account") Is this correct in your case? – Muhammad Jul 08 '18 at 20:05
  • That’s right. You can execute the commands directly using client.command from pyorient. – MichaelR Jul 10 '18 at 22:35