Creating relationships

When working with databases, it's often necessary to create relationships between records.

For example, many to-do list applications let users organize their tasks into distinct projects. To support this behavior, the application must create a relationship between the projects and the tasks. You might say that a project has many tasks and a task belongs to a project.

You can create these type of relationships in FL0 by using the Reference data type.

This tutorial uses a to-do list management application as an example to demonstrate how to use the Reference data type.

Prerequisites

  • You have a FL0 account.
  • You've read the previous tutorials in this series.

Step 1: Create a database table

  1. In the Explorer pane, click Create new.
  2. Select Table.
  3. Type Projects.
  4. Tap the Return key.

Step 2: Configure the database table

  1. Switch to the Configuration tab.
  2. Create a row to store the name of the project.
    1. In the Name field, enter Name.
    2. From the Data type dropdown, select String.
  3. Click Save.

Step 3: Configure the relationship

  1. Open the Tasks table.
  2. Switch to the Configuration tab.
  3. Create a row that references the Projects table.
    1. In the Name field, enter Project.
    2. From the Data type dropdown, select Reference.
    3. From the Reference dropdown, select Projects.
  4. Click Save.

Warning: If the Tasks table has any records in it, you must enable the Nullable option for the Project field. If you don't, an error occurs and your changes won't save.

Step 4: Accept the ID of a project

  1. Open the Insert Task flow.
  2. Open the Start component.
  3. Copy the following JSON Schema into the Input Schema field:
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "isComplete": {
      "type": "boolean"
    },
    "project": {
      "type": "guid"
    }
  }
}
  1. Click the X icon to close the component.
  2. Click Save.

Step 5: Assign tasks to projects

  1. In the Insert Task flow, open the Insert component.
  2. Click + icon.
  3. In the Source Field field, select Body: project.
  4. In the Target Value field, select Project.
  5. Click the X icon to close the component.
  6. Click Save.

Step 6: Retrieve a record with a relationship

  1. Open the Get Task flow.
  2. Open the Select component.
  3. Click Select tab, click + Project.
  4. Enable one or more fields from the Project table.
  5. Click the X icon to close the component.
  6. Click Save.

If you run the flow, the project that's associated with the task appears in the response body.