Connecting Clarity's Distributor Management App
So far you've explored the fundamentals of object relationships, including their types and configurations. Now, it's time to apply that knowledge and add relationships to Clarity's distributor management app. This involves defining a one-to-many relationship between the Distributor Application and Application Evaluation objects using the Model Builder UI. Additionally, to test this relationship, you'll add a custom layout. By completing these exercises, you'll gain practical experience in implementing object relationships within Liferay DXP.
Exercise: Adding a Relationship
Clarity wants to create evaluations for each distributor application they receive. To streamline reviews, they also want to relate each evaluation to its corresponding application. Here you’ll add a relationship between the Distributor Application and Application Evaluation objects.
-
Go to the Distributor Management folder in the Objects application and click View in Model Builder.
-
Click and drag from a connection point on the Distributor Application object to a connection point on the Application Evaluation object.
-
Enter these details:
Field Value Label Application to Evaluations
Name applicationToEvaluations
Type One to Many
-
Click Save.
This adds a relationship table to Distributor Application:
This also adds a relationship field to Application Evaluation:
Liferay also adds dedicated relationship endpoints to the Distributor Application object so you can retrieve and manage related entries via REST APIs. -
Select the relationship to access configuration options in the side panel.
-
Select Cascade for Deletion Type.
-
Click Show All Fields for the Application Evaluation card.
-
Select the Application to Evaluation relationship field to access configuration options in the side panel.
-
Set the field to Mandatory.
Now all evaluations must be related to a Distributor Application entry.
With the relationship established, you can begin linking applications and evaluations. However, before you practice relating object entries, you’ll add a custom layout for test purposes.
Exercise: Adding a Custom Object Layout
While Liferay Objects automatically generates a default UI for each object, this UI does not include relationship tables. Here you’ll create a custom layout for testing purposes.
-
Click Actions (
) for Distributor Application, select Edit in page view, and click Open Page View. -
Go to the Layouts tab and click Add (
). -
Enter
Basic Layout
for name and click Save. -
Begin editing the new layout.
-
In the Info tab, check Mark as Default.
-
Go to the Layout tab, click Add Tab.
-
Enter
Application
for Label, select Fields for Type, and click Save.
-
Click Add Block, enter
General Details
for Label, and click Save.
-
Click Add Field, select Applicant Name, select the Two Column layout, and click Save.
-
Repeat the previous step to add these fields:
-
Applicant Email Address
-
Business Name
-
Business Website URL
-
Business Phone Number
-
Business Tax ID Number
-
-
Click Add Tab.
-
Enter
Evaluations
for Name, select Relationships for Type, select Application to Evaluations for Relationship, and click Save.
-
Click Save to complete the layout.
Great! You can now use the layout to create and relate entries.
Exercise: Relating Object Entries
Once you've established the relationship and configured the layout, you can start creating and linking entries. Here you’ll add and relate distributor applications and evaluations.
-
Open the Global Menu (
), go to the Applications tab, and click Distributor Applications. -
Click Add (
). -
Fill out the form with all mandatory fields.
-
Click Save.
-
Go to the Evaluations tab.
-
Click Add (
) and select Create New.
- Fill out the form with all mandatory fields.
Because you’re adding the evaluation directly from the application's relationship table, the relationship field is automatically set and does not appear.
-
Click Save.
-
Return to the relationship table and verify the evaluation appears.
Notice that Liferay identifies the evaluation entry by its ID.
-
Begin editing the evaluation.
Notice that Liferay also identifies the application entry by its ID.
Great! The relationship works; so you can relate application and evaluation entries. Next, you’ll update both object definitions to use different fields for identifying their entries.
Exercise: Updating Entry Title Fields
By default, object definitions use the ID field for identifying entries in the Liferay UI. However, Clarity wants to use a more readable and meaningful data field. Here you’ll update this value for both Distributor Application and Application Evaluation.
-
Go to the Distributor Management folder in the Objects application and click View in Model Builder.
-
Select the Distributor Application card to access configuration options.
-
For Entry Title Field, select Business Name.
-
Select the Application Evaluation card.
-
For Entry Title Field, select Author.
-
Open the Global Menu (
), go to the Applications tab, and click Distributor Applications. -
Begin editing an application that’s related to an evaluation.
-
Go to its relationship table and verify the evaluation entries are identified using the author field.
-
Begin editing the evaluation and verify the application entry is identified using the business name field.
Conclusion
Congratulations! You’ve implemented and tested a relationship for Clarity’s distributor management app. Defining relationships is essential to building robust and interconnected data models within Liferay DXP. Next you’ll review what you’ve learned before moving on to the next module.
Capabilities
Product
Education
Contact Us