How to embed a vertex into another

45 Views Asked by At

I'm new to OrientDB. I would to know (if is possbile) how to obtain with a select or a match (or other) the following result:

I have an Activity vertex, with an outgoing Has edge to a User vertex.

Activity -Has-> User

// Activity Vertex
{
  "@rid": "#28:0",
  "field_values": {
    "a3b4n": "Foo"
  }
}
// Has Edge
{
  "@rid": "#34:0",
    "field_id": "c7d4j"
}
// User Vertex
{
  "@rid": "#29:0",
  "field_values": {
    "v7d4j": "Bar"
  }
}

I would to get the edge field field_id value and put it into the activity field_values object with the value of the entire User vertex (not the reference).

The result:

// Activity Vertex
{
  "@rid": "#28:0",
  "field_values": {
    "a3b4n": "Foo",
    "c7d4j": {
      "@rid": "#29:0",
      "field_values": {
        "v7d4j": "Bar"
      }
    }
  }
}

Is there a way to perform this ?

1

There are 1 best solutions below

0
On

You can use nested projections:

 SELECT a3b4n, out("Has"):{*} as c7d4j FROM Activity WHERE ...

For reference https://orientdb.org/docs/3.2.x/sql/SQL-Projections.html#nested-projections