Drupal 7架构中的外键问题

lif*_*der 3 drupal foreign-keys drupal-7 drupal-modules drupal-schema

我在模块的Drupal 7架构上遇到了麻烦.有4个表,但样本2就足够了:

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;
}
Run Code Online (Sandbox Code Playgroud)

此代码创建表但不创建外键.我从Drupal.org获得的实现示例:http://drupal.org/node/146939

Drupal版本是7.0-beta 3.作为想法:也许,它还没有实现,我没有在node表中看到它(文档示例指向它的安装程序的代码).

谢谢您帮忙.

Cou*_*sen 5

根据这篇文章,就在几个月前,该hook_schema函数没有实现外键的创建.但是,它可以参考现有的.

也许解决方法是运行外键添加SQL hook_init(或其他API方法之一).对不起,现在似乎没有更好的解决方案.