Bi-directional Express associations

Dec 18, 2024
By myq for Developers

In Concrete CMS, managing bidirectional associations between Express objects can be challenging, especially when attempting to display related entries from both perspectives. This tutorial addresses a common issue: ensuring that associations between Express entries are accessible and display correctly in both directions.

Understanding the Issue

Suppose you want to manage upcoming events for your organization. As a rule, there must be one representative at each event. When two Express objects are associated—such as "Events" and "Representatives"—it's expected that selecting a representative when scheduling an event will reflect appropriately in both objects. However, when setting up such a relationship, users have reported that while an "Event" entry shows the selected representative, the "Representatives" entry does not display the associated events.

Solution Steps

  1. Avoid Using the "Express Entity" Attribute Type for Associations

    The "Express Entity" attribute type is intended for linking non-Express objects (like Pages or Users) to an Express object. Using it between Express objects does not establish a true association, leading to unidirectional visibility. Instead, define explicit associations between your Express objects.

  2. Define Proper Associations Between Express Objects

  • Navigate to the Dashboard > System & Settings > Express > Data Objects.
  • Select one of your Express objects (e.g., "Event").
  • Go to the Associations tab and select Add Association to create a new association:
    • Type: Choose the appropriate association type (e.g., Many-to-Many).
    • Target Object: Select the related Express object (e.g., "Representative").
  • Select Save
  1. Configure Forms to Use Associations
  • When setting up forms for data entry:

    • Go to the Forms tab and edit an existing form or add a new form.
    • In the Form Details, edit or add an Associations form control.
    • Choose the relevant association.

    This ensures that selections made in the form establish proper associations between entries.

  1. Display Associated Entries in Both Directions
  • To display associated entries from both perspectives, use the Express Entry List block:

    • Add the block to your page.
    • In the Source & Search tab, select the Express object you wish to list (e.g., "Representative").
    • In the Results tab, configure the display to include associated entries in the Associations section (e.g., list all "Events" associated with each representative).

    If the associations are correctly configured to allow this bidirectional display, another block set up for the other entity will also show the associated entries:

Additional Considerations

  • Caching Issues: If you experience inconsistencies, it may be due to caching. Clearing the cache or refreshing Express objects can help resolve these issues.

  • Custom Templates: For more advanced displays, consider creating custom templates for the Express Entry List block to format the output as needed.

Recent Tutorials
Restoring deleted pages using advanced search
Jan 16, 2025
By myq.

How to recover deleted pages when there are more than a few to choose from.

How to Automate the Copyright Year
Dec 27, 2024

Learn how to keep your website's copyright year updated automatically in Concrete CMS.

How to change the path of a group of pages
Dec 23, 2024
By myq.

Change the canonical path without breaking things

Bi-directional Express associations
Dec 18, 2024
By myq.

Set up associations between Express entries in both directions

Display Express Data Across Multiple Sites
Dec 17, 2024
By myq.

A guide to configuring Express entities and the Express Entry List block to ensure proper data display across multiple sites.

Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Improvements?

Let us know by posting here.