Foreign keys in Drupal 7 schema problem

I have a problem with a Drupal 7 schema for a module. There are 4 tables, but for sample 2 it will be enough:

function mymodule_schema() {
$schema['series'] = array(
    'fields' => array(
        'id' => array(
            'type' => 'serial',
            'unsigned' => true,
            'not null' => true,
        ),
        'name' => array(
            'type' => 'varchar',
            'length' => 255,
            'not null' => true,
        ),
    ),
    'unique keys' => array(
        'name' => array('name'),
    ),
    'primary key' => array('id'),
);

$schema['sermon'] = array(
    'fields' => array(
        'id' => array(
            'type' => 'serial',
            'unsigned' => true,
            'not null' => true,
        ),
        'title' => array(
            'type' => 'varchar',
            'length' => 255,
            'not null' => true,
        ),
        'series_id' => array(
            'type' => 'int',
        ),
    ),
    'foreign keys' => array(
        'series_id' => array(
            'table' => 'series',
            'columns' => array('series_id' => 'id'),
        ),
    ),
    'primary key' => array('id'),
);
return $schema;
}

This code creates tables, but not foreign keys. Implementation example I get from Drupal.org: http://drupal.org/node/146939

Drupal version is 7.0-beta 3 .. As an idea: maybe it has not been implemented yet, I do not see it in the table node(an example document indicates the code from the installer).

Thank you for your help.

+3
source share
3 answers

, hook_schema . .

, SQL- hook_init ( API). , , .

+5

, :/

, , , , ( , - , , ).

. ( ) ' .

+2

,

'foreign keys' => array(
    'series_id' => array(
        'table' => 'series',
        'columns' => array('id' => 'series_id'),
    ),
),
0

Source: https://habr.com/ru/post/1775898/


All Articles