05. Create the node specific database table

Last modified: July 3, 2006 - 07:02

Our new node form displays. The data validates on submission. We now need to save the node information to the database, as well as our additional information.

Basic node information, such as a node id, node type, title, created by and when, etc., is saved in the node table. The node body is saved in the node_revisions table. This is different in 4.7 from previous versions, which had the body saved in the node table, also.

Our additional information needs to be saved somewhere, so let's create a new table to store our information.

We need a node id field, which will track the node information in the node table. We'll also need a field for the duedate, priority and taskstatus fields we defined in our form.

Drupal uses Unix timestamps (seconds since epoch) to save dates, to maintain portability among different databases, each which may store dates and timestamps differently. Our duedate will be an int(11) field to follow this convention.

For the priority and taskstatus fields, we'll use integer fields to save the values. Recall that for future versions, these fields may be configurable, and any new values added need to be assigned unique numbers, so we'll allow up to 1000 values, instead of 10 (which is the limit of unique numbers we'd have if we use tinyint(1)).

Our database table looks like this now:

--
-- Table structure for table 'todo'
--
CREATE TABLE todo (
  nid int(10) unsigned NOT NULL default '0',
  duedate int(11) unsigned NOT NULL default '0',
  priority tinyint(3) unsigned NOT NULL default '0',
  taskstatus tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY (nid)
)
DEFAULT CHARACTER SET utf8;

Later, we'll create an install file to install this table into the database automatically. For development, at this point in the process, however, you'll need to create this table by hand.

 
 

Drupal is a registered trademark of Dries Buytaert.