Understanding lookup fields

A lookup field (also known as a foreign key) is how AppGini links 2 fields from 2 tables together. For example, let's say that our database contains a products table, a suppliers table, and a product categories table.

Tip: The list of video tours to the left of this page contains some helpful videos explaining several features of lookup fields. It takes less than 20 minutes to watch them all. So, please do.

The products table stores data about each product, including the supplier of the product, and the product category. Since suppliers and categories are stored in their own tables, the products table should look up those two tables when storing supplier and category data for each product.

The products table is thus a child table that has 2 parent tables: suppliers and categories. To achieve this, we should create a field in the products table to hold supplier data, and another one to hold category data. Each of these two fields is called a lookup field. We can define its properties in the Lookup field tab of the field properties pane, which is shown above. Lookup fields are also known as foreign key fields.

How will a lookup field appear in the generated application?

The above screenshot shows the detail view of the products table as generated by AppGini. The detail view is where users can edit records of the table. The "Supplier" and "Category" fields are lookup fields that bring their data from the suppliers and products tables, respectively. This data is represented in a drop down menu for each field.

How to set up a lookup field?

To set a field as a lookup field in AppGini, create a new field and, in its properties pane, go to the "Lookup field" tab, as displayed in the above screenshot. From the "Parent table" drop down, select the table that contains the source data. From the "Parent caption field part 1" drop down, select the source field.

You can optionally specify a second source field to be joined to the first one. For example, you could create a lookup field that lists the full name by joining a "first name" field to a "last name" field, using a space as the separator.

Note: AppGini will change the data type of the lookup field to be the same as that of the primary key of the parent table. This is normal behavior and you shouldn't alter it. If the parent table doesn't have a primary key yet, you should change the data type of the lookup field manually to match the primary key once you create one.

Displaying lookup fields as an options list

AppGini makes it possible to display the lookup field as an options list (radio buttons list) rather than a drop-down menu, as shown above. To do so, simply check the "Show as radio buttons" option in AppGini, as shown below.

Related screencasts

AppGini lookup fields and master detail pages

Using auto-fill look-up fields to automatically populate fields from another table

Creating cascading drop downs with AppGini