如何最好地根据2个顶点共有的属性创建边?

时间:2016-10-29 05:57:44

标签: database orientdb graph-databases orientdb2.2

我有两个顶点类--EMPLOYEE和BRANCH,它们都填充了数据,我希望边缘类InBranch成为它们的关系。

So Employee -InBranch->分支。

具有属性的类员工 - > empname,branchname。
具有权利的类别分支 - >分支名称

取代共同财产(branchname)作为关系,我想将这些作为边缘(InBranch)

我正在努力使作品成为类似于下面的结构:

CREATE EDGE InBranch FROM (SELECT FROM Employee) TO (SELECT FROM Branch) WHERE Employee.branchname = Branch.branchname

在Luca Garulli的代码之后直观地模式化:

create edge Owns from (select from Person) to (select from Country)

来自OrientDB: Using Schemas with Graphs, Part 1

1 个答案:

答案 0 :(得分:1)

你不能直接通过sql来做,但你可以使用JS函数:

var g = orient.getGraph();
var emp = g.command('sql','select from Employee');

for each (a in emp){
  br = g.command('sql','select from Branch where branchname = "' + a.getProperty('branchname') + '"');
  for each (b in br){
    g.command('sql','create edge inBranch from ' + a.getId() + ' to ' + b.getId());
   }
}