Relationships - Documentation topics on: relating content,relating structures,relationships,.


A dotCMS Content Architect or Webmaster can add Relationships between Content Types when the two Content Types in question need a mandatory relationship between eachother or when the one Contentlet will be used in dynamic pulls to display the other.  For instance, a Player Content Type might need a mandatory relationship to a Team Content Type so that no player can be entered into dotCMS without being related to a Team. This case scenario would be best handled by establishing a relationship.

Adding a Relationship between Two Content Types

To add a Relationship between Content Types, first click on the Content Types Tab, click on the drop down arrow next to "+Add New Content Type", choose "Add New Relationship".

Add New Relationship

Step One: In the Add/Edit Relationship window, choose which

  • Content Type will be the "Parent Content Type" and which will be the "Child Content Type".  In the example of "Team" and "Player" Content Types, the Team would be the parent and the Player the child because a players are subsets of a team.  In the example of the "Documentation" to "Screencast" Content Types, the Documentation Content Type becomes the "parent" because one or more Screencast Contentlets will be created in support of each piece of Documentation.

    Step Two: Type the "Parent Relation Name" and the "Child Relation Name" whose combination becomes the title of the relationship, in this case, "Team-Player"

    Relating Two Content Types

    Step Three: Choose a "Relation" - either "One to Many" or "Many to Many" to limit how many pieces of Content can be related to eachother on either side of the Relationship.  Ex: In the case of a "Team-Player" relationship a "One to Many" Relation could be used if each player where allowed to belong to only one Team at a time.  A "Many to Many" Relation would allow a Player to belong to (be related to), any number of Teams.

    Step Four: Choose the "Is a Parent Required" checkbox to force a Relation to a piece of Parent Content when a piece of Child Content is created.  Choose the "Is a Child Required" checkbox to force a Child Relationship when Parent Content is created.

    Step Five: Save the New Relationship.

    Relationships Field

    Adding a Relationships Field to a Content Type

    Relationship fields are typically added on the child Content Type to expose a field for Content Contributors to "tie" a related piece of parent content (team), while adding a piece of child content (player).

    Edit the child Content Type, and add a "Relationships" field so that users can search for a piece of related "parent" content, and relate as children are being added to the system.  To add a Relationships field, simply click on the "+Add New Field" button and choose a "Relationships field" as a display type.  Give the relationships field a generic name such as "related content" and save the field to the Content Type (see below).

    Relate Child Content to Parent

    To view the newly created relationship, click on the down arrow next to "Add New Content Type" button and select "View all Relationships".

    Examine Relationships

    After creating the relationship between Content Types, Content created on either Content Type can be related to one another.  For more information on creating related content, please see the documentation section on RelatingContent.

    Deleting a Relationship between Two Content Types

    To delete a relationship between two Content Types, click on the red X under the "Action" column to the left of the relationship name. Please note that a full re-index and cache flush from the maintenance portlet is recommended after deleting relationships. Re-establishing a relationship of the same name, using the same two Content Types, will not be allowed by the system until the cache clear and re-index have completed.