In this last section you will create the page containing the form that allows adding new entries in the detail table, automatically adding the value for the foreign key A foreign key is a field from a database A database refers to data organized and stored on a computer that can be searched and retrieved by a computer program. Most industrial-strength and many smaller database applications can be addressed using SQL (Structured Query Language). table that refers to (or targets) a specific key, usually the primary key A primary key is one or more table columns whose values uniquely identify each record in a table. In general, a primary key is defined on a single column, but it is not uncommon to have it defined on two columns., in another table. This is a convenient way of logically linking information from related tables in the same database. For instance, a table that stores information about products can contain a foreign key that references the primary key field in a table that stores manufacturers. This way, each product has an associated manufacturer – its associated foreign key points to the unique identifier of the manufacturer. Please note that the foreign key is not unique, but the referenced field (the primary key in the referenced table) usually is. field that stores the association to the master table.
To create this page, follow the next steps:
Open the detail_form page in Dreamweaver.
Apply the NeXtensio Form Wizard, as for the Master Form. Remember to change the table to use to contacts_con, and the UI persistence will do the rest.
The only thing to consider is to remove the idcom_con field from the list presented at step two of the wizard.
After you've finished the wizard configuration, click the Finish button to close it and add all elements into the page.
When updating an existing contact for the currently selected master company, the idcom_con field is not required. When adding a new contact however, you have to add a value for the idcom_con field, to associate the contact with a company. And since the form is a detail for a specific company, using a drop-down menu is not right. Since the company ID is already known (being passed through the id_com URL parameter added to the Add new link), you can add directly its value to the transaction.
To add new fields to existing transactions, you will use the Add Transaction A transaction is a group of SQL statements whose effects are logically connected. Anything from simple queries to inserting, and deleting operations can be considered a transaction, as well as more complex groups of several statements which accomplish a specific task. Fields server behavior A server behavior is a reusable component for server-side development. They add blocks of code to your pages for accomplishing specific tasks. Dreamweaver comes with several default server behaviors and the InterAKT extensions add many more to this list.. Access it from the Server Behaviors tab > + > MX Kollection > Forms > Advanced.
In the dialog box that opens, click the Plus (+) button to add a new field. From the list that is displayed, select the idcom_con field.
For its value, which you can set through the text field at the bottom of the page, enter the following InterAKT mark-up: {GET.id_com}
At this point, the idcom_con column is added to both transactions that exist on page: the insert and update. As mentioned at step 5, the update transaction does not require the presence of this field.
To make the field available only to the insert transaction follow the next steps:
Switch to the Advanced tab of the dialog box.
Select the update transaction in the grid (its name starts with update, so it is easy to spot) and click the minus (-) button on top of grid.
Only the insert transaction, must remain in the list, as you can see in the image below.
Now save the page and upload it to the server.
You can test out the pages you've created, starting with the master list, and through the created links, navigate the details. If you add a new detail record A database row from the detail table. The detail table is defined by a many-to-one relation to another table (the master table), it will belong to the master company selected in the first page.
Good candidates for the master-detail situation are also tables that use self foreign keys. To learn more about tables and self foreign keys, read this article. One such table would contain a column storing the parent's ID. As an example, consider a table that stores categories for products. If you want to use sub categories (e.g. under electronics, you want to have microwave ovens, refrigerators and more) you can do it without using yet another table (that would be unpractical). Simply use a column that stores for the parent of the current category, and for the top-level categories use NULL.
The structure of a table using self foreign-keys is as follows:
To create the NeXTensio master and detail lists and forms, the steps are similar with the ones taken for the two table case, with the following differences:
The master list must display only records that are top-level. To do so, you must manually alter the recordset and add the condition (e.g. idctg_ctg IS NULL)
The detail link in the master list page will have to pass the category ID as URL parameter.
In the detail list page, the recordset must retrieve only records that have the self foreign key equal to the URL parameter passed from the master list (e.g. the main category's ID).
The add new link in the detail page will have to pass the main category ID as URL parameter to the form. This value is in fact the value of the self foreign key for the current set of records (e.g. the idctg_ctg column value).