2016-04-04 5 views
-1

私はBookと呼ばれるOrientDBにクラスを持っています。本にはauthorというプロパティがあります。これはString型で、著者名が含まれています。著者名も同じAuthorクラスがありますが、今はこれらの2つのクラスを接続したいと思います。要するにOrientDBのStringプロパティからLinkへの移行方法は?

、私はなど、名前を持つAuthorクラスに、LINKの参照にバイオをauthorプロパティを移行したい

だから私は、私の本を移行する必要があるが、私はどのように行うのかこれは私のデータを失うことなく?

+0

私が移行したJavaScriptで関数をやっている、あなたは、グラフとして、あるいは文書としてあなたのDBを使用していますか? –

答えて

1

また、(私はそれを試してみてくださいdin't)のようなものを実行できます:私は、この機能を使用し、この構造

enter image description here

enter image description here

で試してみました

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

ありがとう!最後に、同様のアプローチを使用して、@ridを新しいプロパティに割り当て、最後に名前を変更しました。 –

1

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

+0

ありがとうアレッサンドロ!私は同様のアプローチで終わったが、JavascriptではなくJavaで終わった。私はグラフをbtwとしてではなく、Document/Object dbとしてDBを使用しています。 –

関連する問題