Tutorial: Relational Data

Relational data happens when some information you’re storing in a table is linked to another records in another table. A good example is how comments on a blog post can be linked to the post itself and to the author of the comment, like shown in the screenshot below:

A sample set of tables showing the links between the keys and tables.

The comments table has three keys (I drew the arrows showing the links between tables):

Remember that records always have a Record ID. The ID key does not appear in the Data Modeler screen but you can see them in the Data Viewer.

For this tutorial, we’ll create a simple demo to show book quotes. This demo will have two screens with one layout on each screen. On the first screen, the user will select the book and that will navigate to the second screen where a layout will show quotes from that book.

We’ll not spend too long on how to create layouts and interfaces on this tutorial, you need to go through the database tutorial first if you don’t remember how to do it.

Creating the tables

Let’s create two tables: Book and Quote. Since this is just a demo we’ll make the tables as simple as possible. For the Book table we’re just having a single key to hold the book title. In the Quote table we’ll have a key to hold the quote text and one to hold a Record ID from the Book table.

A simple way to store book quotes.

Adding data

Instead of creating an interface to add data, we’ll just use the Data Viewer to insert it. Just double-click on a line and start typing. Appli will create the record for you. Notice that your IDs will not match the ones in the screenshot.

Book table with data.

You can use the context menu on a Record ID to copy the ID and paste it on another table.

Copying an ID.

Then on the Quote table, you can paste that ID into the Book ID field for a new record and then add the quote you want. For this tutorial you can make the quotes up, I copied them from the Internet.

Data for the Quote table.

Make sure the Book IDs match Record IDs from the Book table, that is how we link them.

Creating the books screen

Add a layout and a text element to the layout. Link them to the Book table using no-code, exactly how you learned to do in the database tutorial.

Layout with a text element.

When you switch to play mode, you should see a list of the books you added to the database.

Showing all books.

The low-code actions for this screen will be very simple. We’ll simply store the ID for the clicked book in a variable and move to the quotes screen.

Actions for the layout.

Creating the quotes screen

This is where the magic will happen. Make it just like the previous screen, just a layout and a text element.

Interface for the quotes screen.

Using no-code, link that layout to the quotes table but make sure you check the don’t update on start checkbox. If you don’t do it, the screen will show all quotes when it opens instead of just the ones from the book you selected. If you check this and switch to play mode, the layout will be empty. This is intentional, we don’t want the layout to fetch records by itself, we want to tell it what records to display and we’ll do it by adding actions to the openScreen event of this screen.

No-code configuration for the quotes layout.

How to query a table based on data from another table

The openScreen event is the first event to trigger when we navigate to a screen, so it is the best place to put our code. Our first step is to Reset Layout making sure it is empty. If we don’t do it, the layout will show the previous results in it for a split second when the screen opens.

To get the quotes for the selected_book, we’ll use the Query Records action. This action allows us to filter a table for records matching a criteria we specify. We’ll configure that action to use the following arguments:

The result from executing this action is that we’ll populate the quotes variable with a list of matching records. The next step is to tell the layout to display the records from the list, you can do that with the Display Records In Layout action. Just select which layout to use and pass the variable quotes as the recordIDs argument.

Actions for the openScreen event.

Now if you move back to the first screen and switch into play mode, you can select a book and see the quotes in the quotes screen.

Quotes for the selected book.

Next steps

Check out the database actions, they are very powerful and allow you to do complex data manipulation with very few actions. You might also want to check our advance topics playlist on YouTube.

This chapter was last updated on Fri 17 Jan 2025 13:58:00 GMT