Link creation confusion

I’m pretty new to OrientDB. I’ve had success creating and populating a graph database for my project (javascript and python). I want to supplement the graph with a few document classes. My issue is understanding links.
For edges I created an subclass and then used ‘create edge’ to create the edges. For links, I see a ‘create link’ but I’m not sure how to create the links. Do I need to declare a property of type LINK in each of the document class? What does the INSERT statement syntax to link the two together? I find the documentation to be very vague.

Hi @hethcox

Please ignore the CREATE LINK statement, it’s for another purpose.

To create links, you just have to assign record ID values to document properties.
Eg.

INSERT INTO Person SET name = 'John'; //suppose it returns #12:0

INSERT INTO Person SET name = 'Frank', father = #12:0; //suppose it returns #12:1

UPDATE Person SET son = #12:1 WHERE name = 'John';

Now you have two documents that link each other.

You can do the same with link collections, eg. [#12:0, #12:1] is a valid link list and can be assigned as a value to a document attribute

Thanks

Luigi

Thanks Luigi

I got the relationship working. Is there a single statement SQL statement that will pull back the parent and child record or do I issue two separate queries?

Regards,
John

Hi @hethcox

You can use nested projections to retrieve both, eg.

SELECT *, child:{*} FROM YourClass

Though, typically, the best way to do this is to use edges instead of links and then use MATCH statements to retrieve all the involved nodes in the pattern

Thanks

Luigi

Excellent. Thank you.