Database Map
Many frameworks today have models defined for each database table. Nicotine Framework comes with a new concept called "Map", through which the connection keys between tables are defined in the /workspace/db/map.php file. Once a relationship between two tables is defined, for example, from table A to table B, it is not necessary to define the inverse relationship, from table B to table A.
The concept is based on the fact that each table has a primary key, called "id", which is an integer number, unsigned, not null, auto increment.
See definitions from the next example:
<?php
declare(strict_types=1);
namespace workspace\db;
use nicotine\Registry;
Registry::set('map', [
// Table 'authors'.
'authors' => [
// Table 'books'.
// Relationship: many 'authors' to many 'books'.
'books' => [
// Pivot table for 'many to many' relationship.
'pivot' => 'authors_books',
// Join key related to this 'books' table.
'link' => 'author_id',
// Join key related to parent 'authors' table.
'parentLink' => 'book_id'
],
// Table 'profiles'.
// Relationship: one 'author' to one 'profile'.
'profiles' => [
// Foreign key of this 'profiles' table, related to parent 'authors' table.
'link' => 'author_id',
],
// Table 'addresses'.
// Relationship: one 'author' to one 'address'.
'addresses' => [
// Foreign key of this 'addresses' table, related to parent 'authors' table.
'link' => 'author_id',
],
],
// Table 'addresses'.
'addresses' => [
// Table 'streets'.
// Relationship: many 'addresses' to one 'street'.
'streets' => [
// Foreign key of this 'streets' table, related to parent 'addresses' table.
'link' => 'address_id',
],
],
// Table 'streets'.
'streets' => [
// Table 'houses'.
// Relationship: one 'street' to many 'houses'.
'houses' => [
// Foreign key of this 'houses' table, related to parent 'streets' table.
'link' => 'street_id'
],
],
]);
?>