orientechnologies / orientjs

The official fast, lightweight node.js client for OrientDB
http://orientdb.com
Other
326 stars 68 forks source link

Invalid TO vertex for edge when using Batch updates #333

Closed sudhamab closed 6 years ago

sudhamab commented 6 years ago

Hi Team,

I am using OrientJS version 3.0.0-beta.1

And trying to do a batch update using code as below

      let someValidUserRid = "#1:0";
      let arrayOfBookNames = ["Harry Potter", "Advanced OrientJS"];

      let batch = `begin; 
        foreach ($bookname in :booklist) {
          let $v1 = update Book set name = $bookname UPSERT where name = $bookname;
          let $e = create edge Owns from :user_rid to $v1;
        } 
        commit;
        return  $e;`;

      return session
      .batch(batch, {params: { booklist: arrayOfBookNames, user_rid: someValidUserRid}})
      .all()

However, I get an error "Invalid TO vertex for edge". I was expecting to get a reference to the updated record and then use that to create an Edge from the User to that Vertex.

I faced the same issue when using transactions as well.

Am I missing something?

luigidellaquila commented 6 years ago

Hi @sudhamab

Please try to add a RETURN AFTER to the UPDATE statement:

update Book set name = $bookname UPSERT RETURN AFTER where name = $bookname;

Thanks

Luigi

luigidellaquila commented 6 years ago

Hi @sudhamab

I found a bug and fixed it, it will be released with OrientDB v 3.0.8

Thanks

Luigi

sudhamab commented 6 years ago

thanks Luigi! Glad you found the issue