Overview #
The Table Join (Lookup Table) field type in Custom Tables allows you to create relationships between different tables, similar to MySQL lookup tables (LEFT JOIN). This enables you to reference data from one table within another using primary keys.
This is particularly useful when you want to:
- Retrieve specific field value from the linked (lookup) table.
- Maintain centralized reference data (like countries, cities, or regions)
- Avoid data duplication
- Ensure data consistency across records
Key Features: #
Access any field from the linked table using the tag:
{{ fieldname.get('linked_table_field_name') }}
Retrieve the raw, unprocessed value of a field from the linked table with:
{{ fieldname.getvalue('linked_table_field_name') }}
Display the linked table record processed through a specified layout using
{{ fieldname.layout('layout_name') }}.
Purpose: This field type is ideal for creating relationships between tables, such as linking a ‘Products’ table to a ‘Categories’ table or any other scenario where data from one table is referenced in another.
Field Type Parameters: #
Table
(optional) – Type the name of the Custom Table to join/link with.Field Name
(optional) – Type the field name to return the value by default.Filter
(optional) – Limits records using filter. Example: [age>30] where age is a field in joining tableDynamic Filter
(optional) – Requires that joining table contains Table Join field to use it as a Category FilterOrder By
(optional) – Field name to sort record byAllow Unpublished
(optional) – Allow to select unpublished records.- (No – default)
- true: Yes
Selector
(optional) – How to select records.- dropdown – (Dropdown List)
- radio – (Radio)
Add Foreign Key
(optional) – A FOREIGN KEY is a key used to link two tables together. The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables. Like deleting table records. Enabled by default.- addforeignkey – (Add Foreign Key)
- noforeignkey – (No Foreign Key)
Value Processing Parameters: #
Basic usage:
{{ FieldName }}
Pure Value (Unprocessed): #
Example:
{{ FieldName.value }}
Edit Record Parameters: #
The Table Join field type Twig tag ({{ FieldName.edit }}) for generating a Select Box takes the following parameters:
Basic usage:
{{ FieldName.edit }}
Usage with parameters:
{{ FieldName.edit(CSS Class, Attributes, Parent Selector, Title Layout, Menu Item alias, Improve Select Box) }}
CSS Class
(optional) – Name or names of CSS class(s) to style the select box.Attributes
(optional) – Optional attributes like disabled, onclick, onchange, etc. that can be added to the select box.Parent Selector
(optional) – Used for multilevel dependencies like Country, City, Street.It comprises a list of parameters to set the sub-level select box. Examples include table names, field names, filters, and sorting orders for sub-level selections. It can accept multiple selectors for various dependencies.[city_table_name, city_field_name, allow_unpublished, filter, order_by]
It is also possible to pass multiple selectors.
[ [city_table_name, city_field_name],[country_table_name, country_field_name, false]]
Title Layout
(optional) – Optional parameter setting the option title format instead of using the field name. The layout may contain field names surrounded by curly brackets for customized title display. Example: {{ name }} – {{ title }}Menu Item alias
(optional) – Menu Item alias to open the link using specific menu item parameters.Improve Select Box
(optional) – An option to improve the select box UI, allowing in-list search and other visual enhancements.- (Default. Standard)
- improved – (Improved (Joomla))
- virtualselect – (Improved (Virtual Select))
Example:
{{ FieldName.edit("inputbox","data-importance='max'",[[city_table_name, city_field_name],[country_table_name, country_field_name, false]],,"home-page","improved") }}
Read selected field processed value from joined table: #
Field name – Specify the name of the field to get the value from.
Value Processing Parameters – An array of parameters to process the Joined Table field value. (Optional)
Example:
{{ FieldName.get("birthdate",["Y-m-d"]) }}
Read unprocessed (pure) value of selected field of joined table: #
Field name – Specify the name of the field to get the value from.
Example:
{{ FieldName.getvalue("country") }}
Render the value of joined table using selected layout.: #
Layout – The layout to render joined table record.
Example:
{{ FieldName.layout("PersonProfileLayout") }}
Example Scenario #
Let’s walk through a practical example using countries and cities.
Table Structure Countries Table:
+------------+--------------+
| Field | Type |
+------------+--------------+
| id | Primary Key |
| name | Text |
| population | Integer |
+------------+--------------+
Sample data:
+--------------+------------+
| name | population |
+--------------+------------+
| United States| 331002651 |
| Japan | 125360000 |
+--------------+------------+
Cities Table:
+------------+--------------+
| Field | Type |
+------------+--------------+
| id | Primary Key |
| name | Text |
| country_id | Table Join |
| population | Integer |
+------------+--------------+
Setting Up the Table Join #
In your Cities table, create a new field called “country” Set the field type as “Table Join” Configure the field:
Select “countries” as the table to join with Choose “name” as the default display field The relationship will use the primary key of the countries table
Usage #
In the Admin Interface When adding or editing a city record, you’ll see a dropdown menu showing all available country names.
In Layouts #
You can display the joined data in several ways:
<!-- Display the default field (country name) -->
{{ country }}
<!-- Access country population from the joined table -->
{{ country.get("population") }}
<!-- Example: Full city information -->
City: {{ name }}
Country: {{ country }}
Country Population: {{ country.get("population") }}
Table Join List A variation of Table Join that allows selecting multiple values:
Functions similarly to the regular Table Join Enables selection of multiple options from the joined table Useful for many-to-many relationships (e.g., cities that belong to multiple regions)
Additional Features #
Access any field from the joined table using the get() method Filter and sort based on joined table fields Create hierarchical relationships (e.g., Country → Region → City)
Common Use Cases #
Linking cities to countries Assigning regions to locations Categorizing items with hierarchical relationships Creating location-based relationships.
Leave a Reply
You must be logged in to post a comment.