0

I need help in order to update relation at runtime.

I have this use case:

I have created a graph with the following collections: - A (VertexCollection) - B (VertexCollection) - E (EdgeCollection) with relation( A -> B)

at runtme, using Foxx app, I neet to create a new collection (VertexCollection C) and I need to update EdgeCollection with the following relation( A -> [B,C]).

Is there a way to update relation at runtime?

Thanks in advanced, Peter

  • I am not sure that I understand your question correctly: Is C a collection or a vertex in a collection? And what do you mean by "relation( A -> [B,C] )"? Do you want the edge collection to contain edges from vertices in A to vertices in B and C? – Max Neunhöffer Dec 30 '15 at 15:48
  • Did the answers work for you? if yes, can you mark the best of them as 'accepted'? If not, whats missing? – dothebart Mar 08 '16 at 12:11

2 Answers2

2

You create new collections from Foxx with

var db = require("internal").db;
var C = db._create("C");

An edge collection E can contain edges with in arbitrary vertex collections, you create a new edge in E with:

var edge = E.insert("A/xyz", "C/abc", {"someData":12});

to create an edge from the vertex with _key "xyz" in A to the vertex with _key "abc" in C, say.

Does this answer your question?

Max Neunhöffer
  • 1,392
  • 8
  • 8
  • 10x for your reply. Maybe using this method I lose graph functionality. What do u think abaut that? I think that because using arango web interface I can't create an edge between A->C – Pietro Albano Dec 30 '15 at 16:11
  • The webinterface and the js backend checks whether the new edge conforms with [`edge definition`](https://docs.arangodb.com/devel/Glossary/index.html#edge_definition) of your graph definition. So if that doesn't permit a relation betweet `A` and `C`, you aren't allowed to create one. – dothebart Jan 13 '16 at 14:31
  • Is there anywhere a full Foxx controller example demonstrating what is done in this answer? In particular I'm wondering how to get a reference to the edge collection E? Already I have successfully tried creating regular collection documents, backed by models and repositories, as outlined in the documentation and Foxx demos, but I'm still in the dark regarding how to create a controller endpoint for establishing relationships between vertices; do I use model schemas and repositories for that, or maybe just use graph.relation.save(...) (from require("org/arangodb/general-graph")) directly? – Bjorn Thor Jonsson Apr 26 '16 at 00:44
2

In the ArangoDB manual, in section Modify a graph definition during runtime, the following ways for modifying edge definitions at runtime are shown:

Adding a new edge definition to an existing graph:

/* load graph module */
var graph_module = require("org/arangodb/general-graph");

/* load existing graph by name */
var graph = graph_module._graph("myGraph");

/* add a relation for edge collection myEC2, with vertices 
   between collections myVC1 and myVC3 */
var defs = graph_module._relation("myEC2", ["myVC1"], ["myVC3"]);

/* update the existing graph's definition */
graph._extendEdgeDefinitions(defs);

Modifying an existing edge definition in an existing graph:

/* load graph module */
var graph_module = require("org/arangodb/general-graph");

/* load existing graph by name */
var graph = graph_module._graph("myGraph");

/* update the relation for edge collection myEC2, with vertices 
   between collections myVC23 and [ myVC42, myVC99 ] */
var defs = graph_module._relation("myEC2", ["myVC23"], ["myVC42", "myVC99"]);

/* update the existing graph's definition */
graph._editEdgeDefinitions(defs);
stj
  • 9,037
  • 19
  • 33