Defining Object Relationships¶
Available Liferay DXP/Portal 7.4+
Relationships are connections between Object definitions that you can use to link their entities. You can add relationships to any published or unpublished Object, including both system and custom Objects.
Objects provides two types of relationships:
One to Many: You can relate one of the current Object’s entities to multiple entities of another Object. When selected, a new field is added to entities on the child side of the relationship (i.e., the ‘many’ side), while a table is added to the ‘parent’ side (i.e., the ‘one’ side). On the child side, the new field can be added to a Fields Tab in the Object’s custom layout and relates its entities to a single entity on the parent side of the relationship. On the parent side, the new table can be added to a Relationships Tab in the Object’s custom layout and lists all entities related to the current parent entity.
Many to Many: You can relate multiple entities from the current Object to multiple entities in another Object. When selected, a new database table is created for both sides of the relationship. This table can be added to a Relationships Tab in either Object’s custom layout and is used to list all related entities.
Displaying relationship tables requires a custom layout. However, custom layouts are not supported for system Objects. See Designing Object Layouts for more information.
Adding New Relationships¶
Follow these steps to add relationships to an Object:
Open the Objects portlet.
Select the desired Object.
Click the Relationships tab and select the Add button ().
Enter a Label and Relationship Name.
Label: Identifies the relationship in the Objects UI and can be localized after the relationship is created.
Relationship Name: Determines the relationship’s name in the back-end and uses camel case. Once the relationship is published, this value cannot be changed.
Select a relationship Type: One to Many or Many to Many.
If you want to relate entries within the same Object, you must use the One to Many type.
Select an Object to relate to the current Object.
Click on Save.
Once saved, the new relationship can be added to custom layouts for the related Objects. You can then use the relationship fields and tables to relate Object entries to one another.
Configuring Deletion Type¶
After a relationship is saved, you can configure its deletion type. This setting determines how entry deletion is handled when the entry is related to another entry, and it is only available after a relationship is created.
Available options include Prevent, Disassociate, and Cascade.
Prevent (Default): Entries on the parent side cannot be deleted if they are related to any child entries.
Disassociate: Entries on the parent side can be freely deleted without affecting any related child entries.
Cascade: Entries on the parent side can be freely deleted; deleting a parent entry also deletes any related child entries, provided the user has the requisite permissions for the child Object.
Available Liferay 7.4 U26+ and GA26+
You can remove relationships from both draft and published Object definitions. Removing a relationship permanently deletes its field from the related Object definitions. For published definitions, this can affect many records.
For versions before Liferay 7.4 U26/GA26, users cannot delete relationships included in an Object at the time it is published.
Follow these steps to remove relationships from a published Object definitions.
Open the Global Menu (), go to the Control Panel tab, and click on Objects.
Begin editing the desired Object definition and go to the Relationships tab.
Click the Actions button () for the desired relationship and select Delete.
In the dialog window, enter the name of the relationship and click Delete to confirm.