Overview
You can relate entities to each other through the use of entity reference fields.
If you're not sure how this works, let's refresh some concepts.
Diagram
The following diagram shows how a node of the type Product references a Media entity, which in turn references a File entity.
Two different users were involved, and they are referenced as well.
From this diagram you learn several things about this bit of content:
- Node 42 was created by user 7.
- Node 42 references media 862.
- Media 862 was created by user 12.
- Media 862 references file 8349.
- File 8349 was also created by user 12.
- File 8349 does not reference any other entities.
When Drupal is preparing to display this Product node, it will need to load the referenced Media entity and File entity to know which image to actually show and to ensure that the current site user has the correct permissions to view the Media or File entity.
Referential integrity
When Drupal saves an entity (A) that references another entity (B), it will only store the referenced entity (B)'s entity id, not all of B's data. B's data is stored in its own database table somewhere else.
Later, when it's time to load or display entity A, Drupal will know to load additional data from entity B as well, because B is referenced from A.
This is done for two reasons: to save space in the database and to avoid having to update duplicated data in many places. Imagine a user creates 1000 nodes and changes their username. If every node were storing a full copy of the creator's data, now all those 1000 nodes would have to get updated as well.
This principle of using unique identifiers and referencing those identifiers correctly instead of storing duplicate data is called referential integrity, and is fundamental to Relational Database Management Systems (RDMBS) like MySQL, the most often used database system for Drupal sites.
If you want to learn more about referential integrity and other important database concepts, the following links are a good place to start: