Skip to content

Insert records with links #3619

Answered by elprans
alexbilbie asked this question in Q&A
Discussion options

You must be logged in to vote

You don't need both a link from EmailAddress to Person and from Person to EmailAddress, because you can traverse links in backward direction. Here's one way how your schema could look:

type Person extending Entity {
  required property first_name -> str;
  required property last_name -> str;

  # computed link for query convenience
  multi link email_addresses := .<person[is EmailAddress]
}

type EmailAddress {
  required property email -> str {
    constraint exclusive;
  }
  required link person -> Person;
}

Then, to insert email addresses:

INSERT EmailAddress {
  email := "bob@example.com",
  person := (SELECT Person FILTER id = <uuid>...),
};

However, in your case you probably just …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alexbilbie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants