Documentation

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.

Relationship Types

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.

Important

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:

  1. Open the Objects portlet.

  2. Select the desired Object.

  3. Click the Relationships tab and select the Add button (Add Button).

    Click on the Add button in the Relationships tab, then enter a label and name, and select a relationship type and the desired Object.

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

  5. Select a relationship Type: One to Many or Many to Many.

    Note

    If you want to relate entries within the same Object, you must use the One to Many type.

  6. Select an Object to relate to the current Object.

  7. Click on Save.

    After clicking Save, the saved relationship is listed in the Relationships tab.

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.

After creating a relationship, you can configure its deletion type.

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.

Removing Relationships

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.

Important

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.

  1. Open the Global Menu (Global Menu), go to the Control Panel tab, and click on Objects.

  2. Begin editing the desired Object definition and go to the Relationships tab.

  3. Click the Actions button (Actions Button) for the desired relationship and select Delete.

  4. In the dialog window, enter the name of the relationship and click Delete to confirm.

    Enter the name of the relationship and click Done.