The Departments Tab
Now that you know how to define relationships for a tables in your Database object we will look at how to use them. The Departments tab will introduce you to using Relationships with SQL Records.
On the Departments tab you click a button (1) to populate a list of Departments (2). If you select a Department (3) then you are shown the Towns associated with it (4).
Note: All of the scripts that shown in this lesson are in the group "DepartmentsGroup" script.
Displaying Towns Related to the Selected Department
SQL Record objects can retrieve records from tables related to the SQL Record automatically. Here is how it works:
1) Create a SQL Record object using the table you are targeting. In this example the SQL Record object is created by searching the "departments" table for one with the selected 'code'.
2) Tell the SQL Record object to get all records in the "towns" table that are related to the department. The results will be stored in the "towns" key of the array variable theRecordA.
3) Use the data however you need to. This example displays the array in a Data Grid.