Defining and Managing Relationships
Liferay DXP offers flexibility in how you define and manage object relationships. You can use either the default object editor or the Model Builder UI. The default object editor offers a detailed and focused UI for configuring and extending individual object definitions. However, it does not provide a contextual overview of data model relationships.
In contrast, the Model Builder UI provides a visual approach to defining relationships. It represents objects as cards that you can relate by simply drawing lines between them. This visual representation makes it easier to understand how data entities are connected within your data model. For these reasons, Model Builder is preferred for defining relationships.
Regardless of the UI you choose, defining relationships involves specifying a relationship type (one-to-many or many-to-many), configuring the deletion behavior (cascade, disassociate, or prevent), and determining whether the relationship field is mandatory.
Visualizing Relationships with Model Builder
Within the Model Builder, each object card has visual connection points. To establish a relationship, click a connection point for one object and drag to another connection point. This opens a dialog where you can specify the relationship's details, including its label, name, and type. For example, to link the Distributor Application object with the Application Evaluation object, you could click a connection point for the Distributor Application card and drag it to a connection point for the Application Evaluation card.
Alternatively, you can click the Add Field or Relationship button for an object and select Relationship. This opens the same relationship dialog window for specifying its details.
Once you save the relationship, it is visually represented in the Model Builder. You can then further configure its properties, such as the deletion type, using the options available in the right panel.
For published objects, your data entities are connected immediately. To leverage these relationships to link entries via the Liferay UI, you'll need to update your object's entry creation form. You’ll learn more about designing object fields in Module 5. However, relationships are readily available for use via headless APIs without further setup.
Configuring Relationships with Model Builder
After defining a relationship, you can configure its deletion type and determine whether relationship fields are mandatory or optional.
Deletion type determines how objects handle deletion for related entries. In the Model Builder UI, you can configure this setting in the right panel when you select a relationship. Available options include Prevent, Disassociate, and Cascade.
Objects on the child side of a one-to-many relationship inherit relationship fields. In some scenarios, you may want to make these relationship fields mandatory. For example, in Clarity’s ticketing app, they may want to make the assignee relationship field mandatory, so every ticket has an assigned user. Additionally, if you want to restrict access to object data by account, the relationship field for selecting an account must be mandatory.
Conclusion
The Model Builder UI provides a powerful and intuitive way to define and manage object relationships in Liferay DXP. Its visual approach simplifies the process of creating interconnected data models that accurately represent real-world relationships. Next, you’ll explore how to access and manage related data.
Capabilities
Product
Education
Contact Us