Entries point at each other: an article at the articles to read next, a menu at its pages, a button in a block at the page it leads to. Part of what an entry holds lives in its content's JSON, and a reference stored there has no foreign key behind it, so deleting the target leaves the JSON pointing at nothing. Mainstay accepts that, everywhere, rather than treating references in JSON differently from references in columns. A relation is an id, and a read resolves it defensively.
Three ways to point
#[Relation(to: Person::class)]
public ?Person $author;
#[Relation(to: Post::class)]
public array $related;
#[Terms(of: Tag::class)]
public array $tags;
A relation to one type stores the id: one in a column a where can filter on, a list as a JSON list of ids. A relation to several types, to: [Page::class, Doc::class], stores each as its type and id, because an id alone does not say which table it is in. The property says whether it is one or a list: a nullable type or a union of the targets for one, array for a list, which holds none rather than null.
Terms are a list relation kept in rows of the taxonomy's pivot instead of a column, so the reverse question can be asked too. A tag's page is Mainstay::find(Article::class, where: ['tags' => $tag->id]). A global, a class extending GlobalSet, is the third: one per site, with no address, read with Mainstay::global(Layout::class), holding things such as the menu.
Depth
A read follows relations to a depth. The default is 1: the entries an entry points at are loaded, and their own relations are not. depth: 0 loads none of them and depth: 2 goes one step further. Every target is read through the same query every read starts from, so the site, the language, the trash and Gate apply to it as to anything else read. Over the API the depth is capped, at 3 with a token and 1 without, because every step multiplies what one request makes the server write out.
Missing, not broken
A target the read did not load is handed back as an object of its type holding its id and nothing else, with missing set. That covers depth running out, a target in the trash or deleted, one with no translation in the language read, and one of a type the reader may not read. A template asks:
@foreach (collect($entry->related)->reject->missing as $article)
<a href="{{ $article->url() }}">{{ $article->title }}</a>
@endforeach
A missing target keeps its place: written back as it was read, a list keeps the reference, so an entry restored from the trash comes back into the menus that pointed at it. A reference to a type the field no longer names is left out of the read, and out of the next save.
What it costs
Deleting an entry quietly breaks every page that points at it, with no warning when it is deleted and no report afterwards. Every template that follows a relation has to tolerate a missing target, and that is a rule about how templates are written, not something the storage can enforce. Deleting is at least not final: the entry goes to the trash, from which it can be restored, while its address stops answering at once.
The alternative considered was a relations table, written on every save from every reference found, columns and JSON alike, the same trick the path lookup already uses. It would give real foreign keys, make "what links here" a query, and let a delete warn first. It stays possible precisely because it would be derived: it can be built later by reading the content that exists, with no migration of the content itself. Until broken references are a real problem on a real site, a template that skips what is missing is cheaper.