Insert a record, link to another record, and return a value of the initial record

97 Views Asked by At

I have this schema:

module default {

  type Experience {
    property employer -> str;
    property position -> str;
    property time -> str;
    property active -> bool {
      default := true;
    };
    multi link descriptions -> Description {
      constraint exclusive
    };
    property priority -> int32;
  }

  type Description {
    required property description -> str;
    property priority -> int32;
  }

}

I need to insert a Description, link it to an Experience, and then immediately retrieve the id of the inserted Description.

I'm currently using a with block for my initial insert of the Description and adding it to the descriptions of the Experience:

with newDescription := (
  insert Description {
    description := <optional str>$description
  }
)
update  Experience
filter .id = <uuid>$id
set {
  descriptions += newDescription
};
select newDescription.id;

My current understanding is that newDescription will contain the entire Description record, allowing it to be linked elsewhere. After it's been linked I somehow need to get newDescription to be the final result of the query. Currently I'm able to get the Experience as the final result but not the Description.

0

There are 0 best solutions below