OrientDB - 重新应用边缘后显示的多条记录

时间:2015-11-16 05:40:33

标签: orientdb

我有问题。当我第一次创建边时,输出中的记录数就可以了。但是,当我向该类添加另一条记录并再次创建边缘时,我会得到多条记录。这就是我在做的事情。

create class Country extends V
create class Immigrant extends V
create class comesFrom extends E

create property Country.c_id integer
create property Country.c_name String
create property Immigrant.i_id integer
create property Immigrant.i_name String
create property Immigrant.i_country Integer

insert into Country(c_id, c_name) values (1, 'USA')
insert into Country(c_id, c_name) values (2, 'UK')
insert into Country(c_id, c_name) values (3,'PAK')

insert into Immigrant(i_id, i_name,i_country) values (1, 'John',1)
insert into Immigrant(i_id, i_name,i_country) values (2, 'Graham',2)
insert into Immigrant(i_id, i_name,i_country) values (3, 'Ali',3)

create edge comesFrom from (select from Immigrant where i_country = 1) to (select from Country where c_id = 1)
create edge comesFrom from (select from Immigrant where i_country = 2) to (select from Country where c_id = 2)
create edge comesFrom from (select from Immigrant where i_country = 3) to (select from Country where c_id = 3)

select i_id, i_name, out('comesFrom').c_id as c_id, out('comesFrom').c_name as c_name from Immigrant unwind c_id, c_name

我得到如下结果。

Click here to view image of correct records

然后我将另一条记录添加到移民类。

insert into Immigrant(i_id, i_name,i_country) values (4, ‘James',2)

再次创造优势。请注意,新移民属于已经存在的国家。

create edge comesFrom from (select from Immigrant where i_country = 2) to (select from Country where c_id = 2)

我运行如下相同的查询。

select i_id, i_name, out('comesFrom').c_id as c_id, out('comesFrom').c_name as c_name from Immigrant unwind c_id, c_name

现在我得到多条记录如下。

Click here to view image of incorrect records.

我做错了什么。

谢谢!

1 个答案:

答案 0 :(得分:1)

问题是这个命令:

create edge comesFrom from (select from Immigrant where i_country = 2) 
to (select from Country where c_id = 2)

因为如果你只执行这部分:

select from Immigrant where i_country = 2

你可以看到有两个结果:格雷厄姆和詹姆斯。 因此,它将在两个移民(格雷厄姆和詹姆斯)和国家之间创造一个优势。 要避免此问题,您可以使用移民的名称创建边缘。 但是,我添加了几个附件,以便您可以更好地理解。

问题:http://i.stack.imgur.com/NptOt.png

您的解决方案:http://i.stack.imgur.com/PfU6c.png

我的解决方案:http://i.stack.imgur.com/WEEal.png

此致