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
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.
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
- 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.
- 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.