CMS: About Reference Fields in Database Collections

3 min read
Before continuing you may want to read About Database Collections.
Reference fields let you link one collection with other collections. Specifically, a reference field associates an item in one collection with an item in a different collection.

The relationship created between the collections is defined in the collection structure itself. A dataset connected to a collection that has reference fields will have access to all the fields in all connected collections. This lets you connect your elements to fields in all the referenced collections using one dataset.

The value that is displayed in the reference field comes from the Main field of the specific item in the referenced collection. The actual value that is stored in the database is the ID of the referenced item (in other words, the value in the ID system field of the referenced collection). 
  • You can create a reference field that points to the same collection. For example, let's say you have a collection of employees and you want to indicate who someone's manager is. You could create a reference field called "Manager" that points to the same collection, so that your list of managers automatically comes from your list of all employees.
  • You can create reference fields that point to multiple items at a time. For more information, see this article.

Advantages of Using Reference Fields

  • Reference fields help you avoid duplicating your data. They allow you to store your information one time and then reference it wherever you need it.
  • Reference fields help you maintain data integrity across your collections. Because the collections are intrinsically connected with each other, any change in the original data is automatically reflected in the referenced data. If a referenced item is deleted in the Data Manager, an error message appears as well as an indication in the reference field itself.
  • Reference fields let you easily create pages that use the information from all your connected collections, including master-detail layouts. This is especially useful in elements like tables and galleries that can only be connected to one dataset. Reference fields are also useful when working with repeaters.


Let's say you have a music database, with collections for your artists and songs. Your Artists collection contains information about each artist, like a photo and a bio, with the "Artist" field defined as the Main field

Your Songs collection contains information about each song, such as the artist's name and a link to a YouTube video. In this case, you would define the "Artist" field in the Songs collection as a reference field that connects to the Artists collection. The values that appear in the reference field come from the Main field ("Artist") of the Artist collection. The figure below illustrates how this would look.
On your page, you could then connect a table to the Songs dataset, showing the title of each song and the name and photo of the artist. 
Note how the dataset connected to the table lets you connect to fields in two different collections, the Songs collection (Song Title field) and the Artists collection (Artist and Photo). This happened because the collections are connected via a reference field. Now you can display each artist's photo without having to duplicate it for each song they sing.

Did this help?