Adding composer lock for 4.9.8
[phpmyadmin.git] / doc / relations.rst
blob96643dee9db97c09cf21bc75aba8d014b31e1135
1 .. _relations:
3 Relations
4 =========
6 phpMyAdmin allows relationships (similar to foreign keys) using MySQL-native
7 (InnoDB) methods when available and falling back on special phpMyAdmin-only
8 features when needed. There are two ways of editing these relations, with the
9 *relation view* and the drag-and-drop *designer* -- both of which are explained
10 on this page.
12 .. note::
14     You need to have configured the :ref:`linked-tables` for using phpMyAdmin
15     only relations.
17 Technical info
18 --------------
20 Currently the only MySQL table type that natively supports relationships is
21 InnoDB. When using an InnoDB table, phpMyAdmin will create real InnoDB
22 relations which will be enforced by MySQL no matter which application accesses
23 the database. In the case of any other table type, phpMyAdmin enforces the
24 relations internally and those relations are not applied to any other
25 application.
27 Relation view
28 -------------
30 In order to get it working, you first have to properly create the
31 [[pmadb|pmadb]]. Once that is setup, select a table's "Structure" page. Below
32 the table definition, a link called "Relation view" is shown. If you click that
33 link, a page will be shown that offers you to create a link to another table
34 for any (most) fields. Only PRIMARY KEYS are shown there, so if the field you
35 are referring to is not shown, you most likely are doing something wrong.  The
36 drop-down at the bottom is the field which will be used as the name for a
37 record.
39 Relation view example
40 +++++++++++++++++++++
42 .. image:: images/pma-relations-relation-view-link.png
44 .. image:: images/pma-relations-relation-link.png
46 Let's say you have categories and links and one category can contain several links. Your table structure would be something like this:
48 -   `category.category_id` (must be unique)
49 -   `category.name`
50 -   `link.link_id`
51 -   `link.category_id`
52 -   `link.uri`.
54 Open the relation view (below the table structure) page for the `link` table and for `category_id` field, you select `category.category_id` as master record.
56 If you now browse the link table, the `category_id` field will be a clickable hyperlink to the proper category record. But all you see is just the `category_id`, not the name of the category.
58 .. image:: images/pma-relations-relation-name.png
60 To fix this, open the relation view of the `category` table and in the drop down at the bottom, select "name". If you now browse the link table again and hover the mouse over the `category_id` hyperlink, the value from the related category will be shown as tooltip.
62 .. image:: images/pma-relations-links.png
64 Designer
65 --------
67 The Designer feature is a graphical way of creating, editing, and displaying
68 phpMyAdmin relations. These relations are compatible with those created in
69 phpMyAdmin's relation view.
71 To use this feature, you need a properly configured :ref:`linked-tables` and
72 must have the :config:option:`$cfg['Servers'][$i]['table_coords']` configured.
74 To use the designer, select a database's structure page, then look for the
75 :guilabel:`Designer` tab.
77 To export the view into PDF, you have to create PDF pages first. The Designer
78 creates the layout, how the tables shall be displayed. To finally export the
79 view, you have to create this with a PDF page and select your layout, which you
80 have created with the designer.
82 .. seealso::
84     :ref:`faqpdf`