You are here

function advpoll_field_field_schema in Advanced Poll 7.3

Same name and namespace in other branches
  1. 7 advpoll_field/advpoll_field.install \advpoll_field_field_schema()
  2. 7.2 advpoll_field/advpoll_field.install \advpoll_field_field_schema()

Implements hook_schema().

Note: choice_id is necessary as a hidden field to provide a related unique value for each choice field. Each time a choice is removed or reordered, its delta is reset, as is the array provided in the node data. As a result, simply passing an index to the votingapi as the id for a given choice proved inadequate in cases where choice delta changes due to content editing or write-in values being merged.

Initially I had planned to use an auto-incrementing primary key field but this does not work with the custom field API, hence I settled for this solution. The unique value is just a randomized timestamp that has been converted to hex for brevity.

File

advpoll_field/advpoll_field.install, line 26
Advanced Poll Field Install

Code

function advpoll_field_field_schema($field) {
  $columns = array(
    'choice_id' => array(
      'type' => 'varchar',
      'length' => 10,
      'not null' => TRUE,
    ),
    'choice' => array(
      'type' => 'varchar',
      'length' => 500,
      'not null' => TRUE,
    ),
    'write_in' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
  );
  $indexes = array(
    'choice' => array(
      'choice',
    ),
  );
  return array(
    'columns' => $columns,
    'indexes' => $indexes,
  );
}