0

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

所以员工 -InBranch-> 分支。

具有属性的 Employee 类 -> empname、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:使用 Schemas with Graphs,第 1 部分

4

1 回答 1

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());
   }
}
于 2016-10-31T12:05:40.497 回答