relations.rst.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .. _relations:
  2. Relations
  3. =========
  4. phpMyAdmin allows relationships (similar to foreign keys) using MySQL-native
  5. (InnoDB) methods when available and falling back on special phpMyAdmin-only
  6. features when needed. There are two ways of editing these relations, with the
  7. *relation view* and the drag-and-drop *designer* -- both of which are explained
  8. on this page.
  9. .. note::
  10. You need to have configured the :ref:`linked-tables` for using phpMyAdmin
  11. only relations.
  12. Technical info
  13. --------------
  14. Currently the only MySQL table type that natively supports relationships is
  15. InnoDB. When using an InnoDB table, phpMyAdmin will create real InnoDB
  16. relations which will be enforced by MySQL no matter which application accesses
  17. the database. In the case of any other table type, phpMyAdmin enforces the
  18. relations internally and those relations are not applied to any other
  19. application.
  20. Relation view
  21. -------------
  22. In order to get it working, you first have to properly create the
  23. [[pmadb|pmadb]]. Once that is setup, select a table's "Structure" page. Below
  24. the table definition, a link called "Relation view" is shown. If you click that
  25. link, a page will be shown that offers you to create a link to another table
  26. for any (most) fields. Only PRIMARY KEYS are shown there, so if the field you
  27. are referring to is not shown, you most likely are doing something wrong. The
  28. drop-down at the bottom is the field which will be used as the name for a
  29. record.
  30. Relation view example
  31. +++++++++++++++++++++
  32. .. image:: images/pma-relations-relation-view-link.png
  33. .. image:: images/pma-relations-relation-link.png
  34. Let's say you have categories and links and one category can contain several links. Your table structure would be something like this:
  35. - `category.category_id` (must be unique)
  36. - `category.name`
  37. - `link.link_id`
  38. - `link.category_id`
  39. - `link.uri`.
  40. 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.
  41. 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.
  42. .. image:: images/pma-relations-relation-name.png
  43. 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.
  44. .. image:: images/pma-relations-links.png
  45. Designer
  46. --------
  47. The Designer feature is a graphical way of creating, editing, and displaying
  48. phpMyAdmin relations. These relations are compatible with those created in
  49. phpMyAdmin's relation view.
  50. To use this feature, you need a properly configured :ref:`linked-tables` and
  51. must have the :config:option:`$cfg['Servers'][$i]['table_coords']` configured.
  52. To use the designer, select a database's structure page, then look for the
  53. :guilabel:`Designer` tab.
  54. To export the view into PDF, you have to create PDF pages first. The Designer
  55. creates the layout, how the tables shall be displayed. To finally export the
  56. view, you have to create this with a PDF page and select your layout, which you
  57. have created with the designer.
  58. .. seealso::
  59. :ref:`faqpdf`