You are here

function entity_reference_multiple_field_schema in Entity Reference Multiple 7

Same name and namespace in other branches
  1. 7.2 entity_reference_multiple.install \entity_reference_multiple_field_schema()

Implements hook_field_schema().

File

./entity_reference_multiple.install, line 11
Install, update, and uninstall functions for the Entity Reference Multiple.

Code

function entity_reference_multiple_field_schema($field) {
  if ($field['type'] == 'entity_reference_multiple') {

    // Load the base table configuration from the cache.
    $base_tables = variable_get('entity_reference_multiple:base-tables', array());
    $schema = array(
      'columns' => array(
        'target_id' => array(
          'description' => 'The id of the target entity.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'target_type' => array(
          'description' => 'The type of the target entity.',
          'type' => 'varchar',
          'length' => 32,
          'not null' => TRUE,
          'default' => '',
        ),
      ),
      'indexes' => array(
        'target_id' => array(
          'target_id',
        ),
      ),
      'foreign keys' => array(),
    );

    // Create a foreign key to the target entity type base type, if available.
    $entity_types = $field['settings']['target_types'];
    foreach ($entity_types as $entity_type) {
      if (isset($base_tables[$entity_type])) {
        list($base_table, $id_column) = $base_tables[$entity_type];
        $schema['foreign keys'][$base_table] = array(
          'table' => $base_table,
          'columns' => array(
            'target_id' => $id_column,
          ),
        );
      }
    }
    return $schema;
  }
}