1 entityreference.install entityreference_field_schema($field)

Implements hook_field_schema().

File

core/modules/entityreference/entityreference.install, line 6

Code

function entityreference_field_schema($field) {
  if ($field['type'] == 'entityreference') {
    // Load the base table configuration from the cache.
    $base_tables = state_get('entityreference_base_tables', array());

    $schema = array(
      'columns' => array(
        'target_id' => array(
          'description' => 'The id of the target entity.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
      ),
      'indexes' => array(
        'target_id' => array('target_id'),
      ),
      'foreign keys' => array(),
    );

    // Create a foreign key to the target entity type base type, if available.
    $entity_type = $field['settings']['target_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),
      );
    }

    // Invoke the behaviors to allow them to change the schema.
    module_load_include('module', 'entityreference');
    foreach (entityreference_get_behavior_handlers($field) as $handler) {
      $handler->schema_alter($schema, $field);
    }

    return $schema;
  }
}