Skip to content

Related Records

Related records fields embed a list of records from another section inside a record’s edit page. A typical use is showing all the order records that belong to the client record being edited, with links to view, modify, erase, or create them. The field is listed under Advanced Field Types in the field type dropdown.

The field doesn’t create a MySQL column or store any data. It exists only in the section’s schema, and its field name is assigned automatically (in the form __relatedRecords001__).

Field label

Displayed as the heading of the related records panel on the record edit page.

Field type

The type of input the field accepts. Each field type has different options. Related records fields don’t require a field name: one is assigned automatically.

Show for

Limits who can see the related records list: Everyone, Editors and admins, Admins only, or Nobody.

Show if

Shows or hides the related records list on the record edit page based on another field’s value. See List for the operators and custom expression syntax.

The section whose records are listed. Required.

Max Records

Shows only the first N matching records (default 25). Leave blank to show all. The embedded list isn’t paginated; the panel heading reports how many records matched, e.g. “Showing 1 - 25 of 132 related records”.

List Actions

Which action links appear in the list: View, Modify, and Erase add per-row links (View and Modify are checked by default), and Create adds a create button below the list (checked by default). After viewing, modifying, or creating a related record, the user is returned to the record they were editing.

MySQL Where

A MySQL WHERE clause that selects which records from the related table are shown. The default matches records that store the current record’s number in a field named after the parent table and its primary key. For example, a related records field on a clients section defaults to:

clients_num='<?php echo mysql_escape($RECORD['num'] ?? '') ?>'

This assumes the related table has a clients_num field holding the client record number, such as a list field that gets its options from the clients table.

Adds a “see related records >>” link to the panel heading that opens the related section’s list page with this search applied. Enter a standard URL search string, e.g. fieldA_match=value1&fieldB_keyword=value2. Field search suffixes are required: use field_match=, not field=. The default searches for records matching the current record’s number:

clients_num_match=<?php echo urlencode($RECORD['num'] ?? '') ?>

Both MySQL Where and More “Search” Link can contain <?php ?> code. Available variables:

  • DB::$tablePrefix — the database table prefix
  • $RECORD — associative array of the record being edited

The field is rendered as a panel on the record’s edit page (and view page) containing a list of the matching records from the related section:

  • Columns are the related section’s list page fields, the same columns shown on its own record list. Column headers aren’t click-sortable; records appear in the related section’s default sort order.
  • Each row gets view, modify, and erase links according to the List Actions checkboxes. View and modify open the related record with a return link back to the record being edited.
  • The Create button saves the current record, then opens the related section’s editor to create a new record. The current record’s number is passed in the URL as both {table}Num and {table}_num parameters (e.g. clientsNum and clients_num), so a field in the related section with a matching name is pre-filled with it. Saving the new record returns the user to the record they started from.

If the related section has a dragSortOrder field, that column is left out of the embedded list unless drag sorting for related records is enabled in advanced settings.

System field

System fields cannot be edited and have no modify or erase link unless “System Field Editing” is enabled (under Advanced Commands on the field list page). This prevents accidental changes to fields the program relies on.

Related records fields store no data, so there is nothing to output in viewers, and the Code Generator skips them. To display records from another section alongside your records on the website, use the leftJoin viewer option described in Viewer Options.

Documents CMS Builder 3.83