如何从String属性迁移到OrientDB中的链接?

时间:2016-04-04 11:26:08

标签: sql orientdb nosql

我在OrientDB中有一个名为Book的类。该书有一个author属性,其类型为String,其中包含作者姓名。我也有一个Author类,作者的名字相同,但现在我想连接这两个类。

简而言之,我想将author属性迁移到LINK引用,迁移到具有名称,bio等的Author类。

所以我需要迁移我的书,但是如何在不丢失数据的情况下执行此操作?

2 个答案:

答案 0 :(得分:1)

你也可以执行类似的事情(我不会尝试):

update Book set author2 = (select from Author where name = $parent.current.author )
update Book set author = author2
update Book remove author2

答案 1 :(得分:1)

我试过这个结构

enter image description here

enter image description here

我使用了这个功能

var g=orient.getGraphNoTx();
var books=g.command("sql","select from Book");
var authors=g.command("sql","select from Author");
g.command("sql","create property Book.authors Link Author");
for(i=0;i<books.length;i++){
    var book_author=books[i].getProperty("author");
    for(j=0;j<authors.length;j++){
        var author=authors[j].getProperty("name");
        if(author==book_author){
            var query="update " + books[i].getId() + "set authors = " + authors[j].getId();
            g.command("sql",query);
        }
    }
}
g.command("sql","DROP PROPERTY Book.author FORCE");
g.command("sql","UPDATE Book REMOVE author");
g.command("sql","ALTER property Book.authors name author");
g.command("sql","UPDATE Book REMOVE authors");

enter image description here enter image description here