Drupal数据库开发:从表结构定义到查询改写
1. 表结构定义与Schema模块使用
在Drupal开发中,表结构的定义至关重要。例如下面的代码定义了一个表结构:
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t("The book page's {node}.nid."),
),
'bid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t("The book ID is the {book}.nid of the top-level page."),
),
'primary key' => array('mlid'),
'unique keys' => array(
'nid' => array('nid'),
),
'indexes' => array(
'bid' => array('bid'),
),
这个表有三个 int
类型的字段,还有主键、唯一索引和普通索引。在字段描述中使用花括号引用其他表的字段,能让Schema模块构建指向表描述的超链接。