Mastering Data Modeling with Liferay Objects

Course Overview

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.

  1. Go to the Distributor Management folder in the Objects application and click View in Model Builder.

  2. Click and drag from a connection point on the Distributor Application object to a connection point on the Application Evaluation object.
    Click and drag from a connection point on the Distributor Application object to a connection point on the Application Evaluation object.

  3. Enter these details:

    Field Value
    Label Application to Evaluations
    Name applicationToEvaluations
    Type One to Many

    Enter the details for the relationship.
  4. Click Save.

    This adds a relationship table to Distributor Application:

    This adds a relationship table to Distributor Application.

    This also adds a relationship field to Application Evaluation:

    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.

  5. Select the relationship to access configuration options in the side panel.

  6. Select Cascade for Deletion Type.

    Select Cascade for Deletion Type.

  7. Click Show All Fields for the Application Evaluation card.

  8. Select the Application to Evaluation relationship field to access configuration options in the side panel.

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

  1. Click Actions () for Distributor Application, select Edit in page view, and click Open Page View.

  2. Go to the Layouts tab and click Add ().

  3. Enter Basic Layout for name and click Save.

  4. Begin editing the new layout.

  5. In the Info tab, check Mark as Default.

    In the Info tab, check Mark as Default.

  6. Go to the Layout tab, click Add Tab.

  7. Enter Application for Label, select Fields for Type, and click Save.

    Enter Application for Label, select Fields for Type, and click Save.

  8. Click Add Block, enter General Details for Label, and click Save.

  9. Click Add Field, select Applicant Name, select the Two Column layout, and click Save.

    Click Add Field, select Applicant Name, select the Two Column layout, and click Save.

  10. Repeat the previous step to add these fields:

    • Applicant Email Address

    • Business Name

    • Business Website URL

    • Business Phone Number

    • Business Tax ID Number

      Add the fields to the General Details block.

  11. Click Add Tab.

  12. Enter Evaluations for Name, select Relationships for Type, select Application to Evaluations for Relationship, and click Save.

    Enter Evaluations for Name, select Relationships for Type, select Application to Evaluations for Relationship, and click Save.

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

  1. Open the Global Menu (), go to the Applications tab, and click Distributor Applications.

  2. Click Add ().

  3. Fill out the form with all mandatory fields.

  4. Click Save.

  5. Go to the Evaluations tab.

  6. Click Add () and select Create New.
    Click Add and select Create New.

  7. 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.
  8. Click Save.

  9. Return to the relationship table and verify the evaluation appears.

    Notice that Liferay identifies the evaluation entry by its ID.

    Click Add and select Create New.

  10. Begin editing the evaluation.

    Notice that Liferay also identifies the application entry by its ID.

    Begin editing the evaluation. Notice Liferay also identifies the application entry using 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.

  1. Go to the Distributor Management folder in the Objects application and click View in Model Builder.

  2. Select the Distributor Application card to access configuration options.

  3. For Entry Title Field, select Business Name.

    Click the Distributor Application card and select Business Name for Entry Title Field in the configuration side panel.

  4. Select the Application Evaluation card.

  5. For Entry Title Field, select Author.
    Click the Application Evaluation card and select Author for Entry Title Field.

  6. Open the Global Menu (), go to the Applications tab, and click Distributor Applications.

  7. Begin editing an application that’s related to an evaluation.

  8. Go to its relationship table and verify the evaluation entries are identified using the author field.

  9. Begin editing the evaluation and verify the application entry is identified using the business name field.

    Verify entries use the appropriate field for identifying entries in the relationship table and relationship 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.

  • Exercise: Adding a Relationship

  • Exercise: Adding a Custom Object Layout

  • Exercise: Relating Object Entries

  • Exercise: Updating Entry Title Fields

  • Conclusion

Loading Knowledge

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy