Goal: Learn how to create and work with related data models.

Background: A Help Desk ticket usually relates to a specific product but our current application has no way of capturing that detail unless the user includes it in the description or summary… not the best way to capture data! By defining relationships between data models we can capture data in a way that makes it easier to create filters and reports in the future (hint, hint).

Create Relations between DataModels

  1. Select Models under the left-hand Logic menu and add a new model called product.
  1. Double-click the product box to edit it, and add attributes:
    • name, string (text)
    • version, float (decimal)
    • description, string (text)
  2. Adjust the size of the strings and decide how many decimals should be displayed for the version.
  1. Create a relationship between product and issue, by going back to the data model map and grabbing the edge of one model and connecting it to the other. You can rearrange them and adjust the scale to get a better look at it.
  1. Mouse-over the relationship and click the Gear icon to configure the relationship.
  1. Each relationship is two-sided. Click the lines connected to each data model until you’ve established what is shown:
    • product can have zero-to-many issue
    • An issue can have zero-or-one product
  2. Save your app.

Note: You can edit Data Models (& Relations) from both the Diagram and List views.

Use Relations in your Views

  1. Go back to the User Interface menu and edit your EditIssue view.
  1. Add a Select widget and notice that it is automatically configured for the product relationship.
  2. Drag the widgets around until they are organized to your liking.
  1. Now edit the ListIssue view.
  1. Double-click the DataGrid and select the Columns tab.
  1. A new column is now available to display the related product data. Enable the column and configure it.
  2. Save your app.

Go Further!

Before you can try your changes, you need to add some product data records. See if you can use what you’ve learned so far to add an EditProduct view, form and necessary navigation.

When you’re done with that, create a ListProduct view by copying the ListIssue view and editing it.

Go Further!

Add a title to your list views by dragging over a Label widget.

Test Drive

Click the Play arrow on the bottom left to run your app and try it out.

Note:  If the products aren’t displaying correctly, open the product data model and select name for the Advanced Label attribute.

Unless a string attribute is present, the default attribute of ID is used, which is a unique alpha-numeric string.

Note: When defining a relation you can choose a non-zero option like one (1) or one-to-many (1…n). In these cases, zero is not an option so there must be a related data record. For example, if every issue has one (1) product, then when running the app and creating an issue, you won’t be able to save/submit unless you’ve also selected a product.

This can sometimes be problematic during development. For example, think about what would happen if you create a number of issues in your app, and then create a new product data model with a one (1) relation. Your app will load the issue data and expect a related product for each one, and get upset (throw errors) when it doesn’t find any. To avoid these errors you have two main options:

  1. Instead of each issue requiring one (1) product, you can define the relation as zero-or-one (0…1). Since zero is acceptable, no rules are broken and your app will be happy.
  2. Start with zero-or-one (0…1), run your app and add a product to each issue, then change the relation to one (1). This will allow you to update your existing issue records, and will ensure that all future issues have a related product.