CMS: About Connecting Multiple Database Collections

3 min read
Note:
Before continuing, you may want to read About Database Collections.
Each collection in your database is a separate entity. However, you can connect the data in your different collections so that they can work together to display related information. This can be especially useful when working with tables, galleries, and repeaters.

You have two options for connecting information stored in different collections:

Reference Fields

When you create reference fields, you create a pointer to a different collection, creating a connection between the collections in the actual structure of the primary collection. This connection gives you access to all the information in all the referenced collections from within the primary collection. 

When you connect a dataset to a collection that has reference fields, that dataset automatically has access to all the fields in all the referenced collections. This means you can connect page elements  to fields from all the connected collections using a single dataset.

You can also filter a dataset by a reference field. See below for a description.
Note:
Dynamic page URLs cannot be based on reference fields.

Filtering Datasets

Filtering datasets lets you create connections between collections that both have a field with the same data without using a reference field. This lets you set up one dataset to respond to the other, where the first dataset displays only those items whose field values match the same field value for the current item of the second dataset. On a dynamic item page, for example, a filtered dataset will display all the information from the second dataset that matches the current item being displayed on the page. 

What's important to remember is that the connection exists only between the datasets on that page. No other datasets are affected. If you add another dataset connected to one of those collections, you will need to filter it again in order to create a connection. 
Note:
You can filter a dataset by a regular field or a reference field.

How It All Works Together

Once you get your collections working together, you have additional options for building your pages. Let’s look at some ideas.

For example, say you have a database of your favorite music with the following collections.
  • Artists (fields: Artist, Bio, Photo, Website)
  • Genres (fields: Title, Description)
  • Songs (fields: Title, Artist [reference field], Genre, Video URL) 

Here are some ideas of pages you can create based on the Songs dataset. Note how you can include fields from the Artists collection.
  • A regular page connected to the Songs collection. 
    This page has a repeater listing all the songs in your collection, including a photo of the artist from the Artists collection. 
  • A dynamic item page with a dataset for Songs. 
    This page displays the title and a video of the song, and the name and bio of the artist.

Note how in both these cases, the reference field lets you retrieve information that is stored in the Artists collection (the photo, the bio) without attaching a dataset for that collection. 

Now let’s look at some ideas using more than one filtered dataset.
  • A dynamic item page with a dataset for Artists that also has a Songs dataset filtered by the "Artist" field. 
    This page displays each artist name and photo and a table listing all of their songs.
  • A regular page with one dataset for Genres and one for Songs that is filtered by the “Genre” field.
    This page has a repeater connected to the Genres dataset that lists all the genres. Attached to each repeater item is a table connected to the Songs dataset. The table lists the songs that match each genre, including the name and photo of the artist of each song. 
    Note that while this page has two datasets, it can display information from three collections. The photo of the artist comes from the Artists collection, which is available because of the reference field.

Did this help?

|