Edges is entyties which represend connection between two documents. The main idea of Edges is that you can buidl your own graph (tree) between set of documents and make search within hierarchy of documents.
To specify vertex from_document and to_document should be specified during Edge creation
from arango import create
c = create()
c.test.create()
# create FROM document
from_doc = c.test.documents.create({
"sample_key": "sample_value"
})
# create TO document
to_doc = c.test.documents.create({
"sample_key1": "sample_value1"
})
# creating edge with custom data
c.test.edges.create(from_doc, to_doc, {"custom": 1})
Warning
Code below should be implemented by using AQL (Making queries with AQL). Not implemented at the moment.
# getting edge by document
# c.test.edges(from_doc)
# getting with direction
# c.test.edges(from_doc, direction="in")
# assert c.test.edges(from_doc).first.from_document == from_doc
# assert c.test.edges(from_doc).first.to_document == to_doc
Edges are accessible via collection instance for example connection.collection.sample_collection.edges. Usually this expressions looks lot shorter.
Basically via edges shortcut accessible Edges Proxy - Proxy object which have several shortcuts and produce Resultset object.
Below described basic method within Edges proxy:
Warning
This functionality not implmented yet. Use AQL - Making queries with AQL section with custom wrapper to work with Edges.
More details in Edges REST Api documentation of ArangoDB
Edge instance methods consist from basic CRUD methods and additional methods specific obly for Edges:
Edge instance object
Method to create new edge. from_doc and to_doc may be both document-handle or instances of Document object.
Possible arguments: waitForSync
Read more about additional arguments Edges REST Api
This method may raise EdgeAlreadyCreated exception in case edge already created.
Return edge instance (self) or None
Method to update edge. In case from_doc or do_doc not specified or equal to None then current from_document and to_document will be used.
In case save argument set to False edge will not be updated until save() method will be called.
This method may raise EdgeNotYetCreated exception in case you trying to update edge which is not saved yet.
Exception EdgeIncompatibleDataType will be raised in case body of the edge isn’t dict.
Method to delete current edge. If edge deleted this method return True and in other case False
Method to save Edge. This is useful when edge udpated several times via update
Possible arguments: waitForSync
Read more about additional arguments Edges REST Api
This property return Edge content
From vertex, return instance of Document or None
To vertex, return instance of Document or None
This method very similar to dict‘s get method. The difference is that default value should be specified explicitly.
To get specific value for specific key in body use and default (fallback) value 0:
edge.get(name="sample_key", default=0)