# Choosing links and carbon copy when you store content

This guide gives guidance for [Health Network](../core-model/content-graph.md) and [Permissions & Roles](../core-model/permissions.md).

## The question

You are building an application that stores content in OnEarly. Each time it links one piece of content to another, you make two choices: the link kind (`CONTAINS`, `INCLUDES` or `RELATES_TO`) and whether carbon copy is on or off. Which should you pick, so that the right people see the right content, and it lives and is deleted with the right things?

There are many valid ways to store content. What follows is suggestions to consider, not rules.

The link kind and carbon copy are chosen by the application or integration that stores the content.

## What each choice does

| Link kind | Carbon copy on | Carbon copy off |
|---|---|---|
| `CONTAINS` | A share of the parent reaches the child too, with the same rights except Edit. | A share of the parent stops at this link. The child, and the content below it, stays private unless it is shared directly. |
| `INCLUDES` | Anyone who can read the content that holds the link sees the linked content inside it. This goes one link deep: the linked content's own children are not brought along, and the link does not let the reader open the linked content on its own. One exception: a File that its owner included this way can also be opened on its own, read only, by people who can read the content that holds the link. | A reader of the content that holds the link sees the linked content inside it only if they have their own View access to the version the link points at. |
| `RELATES_TO` | Anyone who can read the content that holds the link sees the linked content inside it. This goes one link deep: the linked content's own children are not brought along, and the link does not let the reader open the linked content on its own. | A reader of the content that holds the link sees the linked content inside it only if they have their own View access to the version the link points at. |

A few rules sit behind this table:

- **Ownership and deletion.** Each piece of content has at most one `CONTAINS` parent. Deleting a parent deletes everything under it through `CONTAINS`. Deleting the holder of an `INCLUDES` link leaves the included content in place. `RELATES_TO` has no ownership and no cascade.
- **Which version a link points at.** When the linked content is edited, only `CONTAINS` links into it move to the new version. `INCLUDES` and `RELATES_TO` links stay on the version they were made to.
- **Write access.** A share never gives write access through `INCLUDES` or `RELATES_TO`. A share is followed only through `CONTAINS`.
- **What the person storing the link must hold.** Making or changing a `CONTAINS` or `INCLUDES` link needs Contribute on the content that holds the link. A `RELATES_TO` link needs Edit on the content that holds the link. With carbon copy on, the person must also hold View, Share and Copy together on the linked content. The Viewer and Editor share levels include all three; View only and Contributor do not. With carbon copy off, the person still needs View on the linked content.
- **When your application does not state carbon copy.** The link is stored with carbon copy on, for all three kinds. A link made by a reference field is different: it takes the setting declared on the content type, which is off unless the type sets it on, and a value your application sends is ignored.
- **Changing the setting later.** Your application can change carbon copy on an existing link by making the same link again with the other value. Turning it on needs View, Share and Copy on the linked content. This does not apply to a link made by a reference field: its setting comes from the content type, and a value your application sends is ignored.

## The rule of thumb

Ask these questions about each link.

1. **Is the linked content part of the content that holds the link, and should it be deleted with it?** Consider `CONTAINS`.

   *Example: a request and its steps. A step means nothing without its request, and deleting the request should remove its steps.*

2. **Does the linked content exist on its own, but should show inside the content that holds the link, pinned to the version you linked?** Consider `INCLUDES`.

   *Example: a request that uses someone's Medicare card. The card exists on its own and is used by many requests. Each request keeps showing the card as it was when the request was made, even after the card is renewed.*

3. **Are the two pieces of content peers, with neither owning the other?** Consider `RELATES_TO`.

   *Example: a follow-up note you start from an existing meeting note. The new note relates to the original, each can be shared and deleted separately, and carbon copy off means people who can read the follow-up do not see the original unless they already have access to it.*

4. **Should everyone who can read the content that holds the link also see the linked content?** Consider carbon copy on. Otherwise, consider carbon copy off.

   *Example, on: the Medicare card included in a request. Whoever handles the request needs to see the card.*

   *Example, off: an attendee's link to a contact. People who can read the meeting note should not see your contact record unless you have shared it with them.*

## Worked examples

### Meeting attendees

You store a meeting note with its attendees, and each attendee is a person in your contacts.

| Link | Kind | Carbon copy | Why |
|---|---|---|---|
| Meeting Note to Attendee | `CONTAINS` | On | The attendee entry is part of the note. It is deleted with the note, and a share of the note reaches it. |
| Attendee to Contact | `INCLUDES` | Off | The contact exists on its own and is not owned by the note. The link is made by a reference field, so it takes the setting declared on the content type, and the built-in Attendee type does not set carbon copy on. |

What this gives you:

- Your application cannot turn carbon copy on for the Attendee to Contact link by sending a value. The setting comes from the content type.
- Someone the note is shared with sees the contact inside the attendee only if they have their own View access to the version of the contact the link points at.
- The contact stays in place when the note is deleted.

### Terms of service accepted when making a request

Someone accepts your terms of service while making a request, and you want a lasting record of exactly what they accepted and when. We recommend storing it this way. Request, Terms Acceptance and Terms of Service are types your application would define.

| Link | Kind | Carbon copy | Why |
|---|---|---|---|
| Request to Terms Acceptance | `CONTAINS` | On | The Terms Acceptance holds the date and time of acceptance. It is part of the Request, is deleted with it, and a share of the Request reaches it. |
| Request to Terms of Service | `INCLUDES` | On | The Terms of Service exist on their own and are used by many requests, so the Request should not own them. With carbon copy on, every reader of the Request sees the terms that were accepted. |

What this gives you:

- **The version that was shown.** After you edit the Terms of Service, the `INCLUDES` link keeps pointing at the version that was shown when the request was made.
- **Readers see the terms inside the Request.** Anyone who can see the Request sees those terms inside it, without needing their own access to the Terms of Service. The link does not let them open or change the Terms of Service on their own.
- **What the person making the request must hold.** For the `INCLUDES` link to be accepted with carbon copy on, the person making the request must hold View, Share and Copy on the Terms of Service. The Viewer and Editor share levels include all three; View only and Contributor do not.

### A shared container with a private note and a related email

You keep a file and a note of your own in a container, and the note is about an email. You plan to share the container, but not your note.

| Link | Kind | Carbon copy | Why |
|---|---|---|---|
| Container to File | `CONTAINS` | On | The file is part of the container. It is deleted with the container, and a share of the container reaches it. |
| Container to Note | `CONTAINS` | Off | The note is part of the container and is deleted with it, but a share of the container stops at this link, so the note stays private unless it is shared directly. |
| Note to Email Message | `RELATES_TO` | Off | The note and the email are peers. Neither owns the other, and deleting one does not delete the other. With carbon copy off, a reader of the note sees the email inside it only if they have their own View access to the version the link points at. |

To store the Note to Email Message link, the person needs Edit on the Note and View on the Email Message. With carbon copy on instead, anyone who can read the Note would see the Email Message inside it, and the person storing the link would need View, Share and Copy on the Email Message.

Source: https://docs.staging.onearly.com/best-practices/choosing-links-and-carbon-copy/
