0
votes

I have a OrientDB question. For the statement

INSERT INTO Account CONTENT 
{ name : 'Luca',
  vehicles : {
     @class : 'Vehicle',
     type : 'Car',
     model : 'Maserati',
     isItTrue: false
  }
 }

I get a result (see screenshot), but the class/table 'Vehicle' does not contain any entries. Is this a valid result? I expected that automatically some values are written into 'Vehicle' and connected to 'Account'. Only the column 'vehicles' from 'Account' contains JSON-Data.

Thank you for your response.

Best regards Karo

Screenshot OrientDB

2

2 Answers

2
votes

With your query you are inserting embedded data into Account, if you want to insert some data into Account and Vehicle, you should do it in different queries and then if you want you can connect them with an edge. See example:

create class Account extends v
create class Vehicle extends v
create class owns extends e

create property Account.name String
create property Vehicle.type String
create property Vehicle.model String
create property Vehicle.isItTrue BOOLEAN

insert into Account(name) values ("Luca")
insert into Vehicle(type, model, isItTrue) values ("Car", "Maserati", false)

create edge owns from (select from Account where name = "Luca") to (select from Vehicle where model = "Maserati")

enter image description here

0
votes

Alternatively, if you are not looking to create edges and you just want a link from document to document, the below will give you desired results in single insert / transaction while still keeping your json structure for the linked record

 create class Account
 create class Vehicle
 create property Account.vehicles embedded Vehicle

 INSERT INTO Account set name = "luca", vehicles = [ {
     "@type": "d",
     "@class" : "Vehicle",
     "type" : "Car",
     "model" : "Maserati",
     "isItTrue": false
  }]

enter image description here