Foreign key

From Not Web Design Wiki
Jump to: navigation, search
Quick Links

Main Menu

If you find this article incomplete, please consider to edit it or join the Discussion to make any suggestion.

This field is meant to relate 2 tables within each other.

The most common use of Foreign Key is to create a dropdown menu with the items stored in a table.

Joomla! Foreign-key Field in the Component Creator
Foreign key field settings

How to link 2 tables

First you need to create a source table where the selectable data will be stored. Then, you have to create a second table and add a "Foreign key field". In this same field, you need to select the source of the selectable data on the dropdown menu called "Table". 2 dropdown menus will now show up: "Field Key" and "Field Value".

  • Field key: typically we will use "id" in this field, as it's the unique identifier of each item.
  • Field value: will be the field from the source table which stores the name that will show in the dropdown menu.

The following sample is something any blog extension will use in Joomla.

It's a simple component with 2 tables:

  1. The first table contains the a text field, a WYSIWYG article and a foreign Key field pointing to the second table.
  2. The second table just stores items with a single media manager field.

The Foreign Key field setting can be seen in the picture on the right of the screen.

Common Solutins

How to create a "many to many" (M:N) relationship between tables.


Back to Fields