Contentful logo

Contentful Community

How to link one Content Type to a list of one other Content Type

Hello all,

I’m having some difficulty doing something that would appear very basic.

Here’s an explanation of what I’m looking to do:

I have created two content types - Shopping List & List Items. The List Items are child elements associated with a particular Shopping List. For example:

Groceries (Shopping List)
Oranges, Apples, Bananas (List Items)

Christmas (Shopping List)
Gift 1, Gift 2, Gift 3 (List Items)

For my project, I would use Contentful’s API to query a list of available Shopping Lists. By clicking one of those lists, I could then query Contentful to return a list of items associated with that particular Shopping List.

How would I use the Web App to manually link a collection of List Items to a particular Shopping List? Is this ability also possible programmatically?

I did find this resource about nested entries, however, I can’t locate the links they refer to about linking entries together. See “Adding references to an entry”

https://www.contentful.com/help/references/#nested-entries

Any help, tips, or methods for getting to grips with Contentful would also be appreciated.

Thanks in advance,

Tom :slight_smile:

Hi @ThomasMorgan,

I’m not sure if I understood correctly to connect the List Items in your Shopping List, you will need to create a Reference field in the Shopping List, as one-to-many to List Items. That will guarantee the data structure that you need. In addition, when querying using the Contentful Delivery API, the List Items should already be included in the response.

If not, you can increase the include value:

Hello Alma,

Thank you for your reply.

I think you’re right. Adding a reference field would be what I’m looking for.

However, I refer back to the link I provided in my original post, specifically this section:

  1. In the web app, navigate to the main content list and click the blue Add entry button.
  2. In the entry editor, look for a field with the following links:
  • Create new entry and link : This will open the entry editor in another tab. Create your entry as normal, and publish. It will then be linked to the original entry.
  • Link existing entries : Select an existing entry in your space from the list to link. Click the green Insert selected entries button when finished.

I cannot see “Create new entry and link” or “Insert selected entries” anywhere within the editor or a particular entry or within the Contentful console. Am I looking in the wrong place?

Thanks,

Tom :slight_smile:

Hi @ThomasMorgan, we recently changed the style of the reference and media field editor, now you will need to click on Add Content to create a new reference or insert an existing reference.