Same question here! How to use two sub-insert's nested in a master insert? Btw, it seems this nested insert does not work as a transaction. I found sometimes the sub-insert succeeds but the master insert crashed, and in that case the sub-insert will not rollback.
On Tuesday, May 5, 2015 at 9:36:06 AM UTC-5, Dong Jin wrote: > > When creating a new record with linked elements, it is possible to use > sub-queries for specifying the linked elements. It is even possible, to add > a 'sub-insert' to force OrientDB to insert the linked element in the > sub-insert first, and then insert the main object which maintain a link to > the single element just created before. > > But why is this not possible if the linked element is a collection? > > For the example data structure: > > create class Address > create property Address.street String > create property Address.city String > > create class Client > create property Client.hq link Address > create property Client.subs linkset Address > > I can do the following three alternatives. I can use a sub-insert for a > single linked record (hq). And I can use a sub-query or an array of > record-ids, since the sub-query returns an array of record-ids as well. > > insert into client set name = 'client 1', hq = (insert into address set > street = 'Long street', city = 'London') > insert into client set name = 'client 2', subs = (select from address > where city = 'London') > insert into client set name = 'client 3', subs = [#11:6,#11:0] > > What should I do to achieve the following? Actually, the two insert > statement return two corresponding @rid. > > My goal is to create the addresses and the client object in one statement, > since transaction is almost impossible here. > > insert into client set name = 'client 4', subs = [ (insert into address > set city = 'city 2'), (insert into address set city = 'city 3') ] > > This is the error message I got: > Error: com.orientechnologies.orient.core.exception.OValidationException: > The field 'Client.subs' has been declared as LINKSET but the value is not a > record or a record-id > -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
