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
- In the Explorer pane, click Create new.
- Select Table.
- Type Projects.
- Tap the Return key.


Step 2: Configure the database table
- Switch to the Configuration tab.
- Create a row to store the name of the project.
- In the Name field, enter Name.
- From the Data type dropdown, select String.
- Click Save.


Step 3: Configure the relationship
- Open the Tasks table.
- Switch to the Configuration tab.
- Create a row that references the Projects table.
- In the Name field, enter Project.
- From the Data type dropdown, select Reference.
- From the Reference dropdown, select Projects.
- 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
- Open the Insert Task flow.
- Open the Start component.
- Copy the following JSON Schema into the Input Schema field:
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"isComplete": {
"type": "boolean"
},
"project": {
"type": "guid"
}
}
}
- Click the X icon to close the component.
- Click Save.


Step 5: Assign tasks to projects
- In the Insert Task flow, open the Insert component.
- Click + icon.
- In the Source Field field, select Body: project.
- In the Target Value field, select Project.
- Click the X icon to close the component.
- Click Save.


Step 6: Retrieve a record with a relationship
- Open the Get Task flow.
- Open the Select component.
- Click Select tab, click + Project.
- Enable one or more fields from the Project table.
- Click the X icon to close the component.
- Click Save.


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