Fieldtype::getDatabaseSchema() method

Get the database schema for this field

  • Should return an array like in the example below, indexed by field name with type details as the value (as it would be in an SQL statement).

  • Indexes are passed through with a keys array. Note that pages_id as a field and primary key may be retrieved by starting with the parent schema return from the built-in getDatabaseSchema() method.

  • At minimum, each Fieldtype must add a data field as well as an index for it.

  • If you want a PHP NULL value to become a NULL in the database, your column definition must specify: DEFAULT NULL.

Example

array(
 'data' => 'mediumtext NOT NULL',
 'keys' => array(
   'primary' => 'PRIMARY KEY (`pages_id`)',
   'FULLTEXT KEY data (data)',
 ),
 'xtra' => array(
   // optional extras, MySQL defaults will be used if omitted
   'append' =>
     'ENGINE={$this->config->dbEngine} ' .
     'DEFAULT CHARSET={$this->config->dbCharset}'

   // true (default) if this schema provides all storage for this fieldtype.
   // false if other storage is involved with this fieldtype, beyond this schema
   // (like repeaters, PageTable, etc.)
   'all' => true,
 )
);

Usage

$array = $fieldtype->getDatabaseSchema(Field $field);

Arguments

NameType(s)Description
fieldField

In case it's needed for the schema, but typically isn't.

Return value

array


Fieldtype methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #519
    In the 519th issue of ProcessWire Weekly we'll check out a new third party module called RockForms, introduce the latest ProcessWire core updates, and more. Read on!
    Weekly.pw / 20 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK