1

Right now, I am touching the database for drupal 7. I searched about the difference between "commerce_line_item" table and "field_data_commerce_line_items" table. But no luck.

Does anyone know the difference between them? Also, is there any reference that I can follow to check the table explanation?

I really appreciate anyone's help.

UPDATE

Based on everyone's help and my own opinion, I drew a simple diagram for these two tables:enter image description here

1

commerce_line_item is the base table of entity with same name. The entity is defined from the sub module commerce_line_item in Commerce project. You can find the definition from its code repository

commerce_line_item.module

/**
 * Implements hook_entity_info().
 */
function commerce_line_item_entity_info() {
  $return = array(
    'commerce_line_item' => array(
      'label' => t('Commerce Line item'),
      'controller class' => 'CommerceLineItemEntityController',
      'base table' => 'commerce_line_item',
      'fieldable' => TRUE,
      'entity keys' => array(
        'id' => 'line_item_id',
        'bundle' => 'type',
        'label' => 'line_item_id', // TODO: Update to use a custom callback.
      ),
      ...

commerce_line_item.install

function commerce_line_item_schema() {
  $schema = array();

  $schema['commerce_line_item'] = array(
    'description' => 'The base table for line items.',
    'fields' => array(
      'line_item_id' => array( ... ),
      'order_id' => array( ... ),
      'type' => array( ... ),
      'line_item_label' => array( ... ),
      'quantity' => array( ... ),
      'created' => array( ... ),
      'changed' => array( ... ),
      'data' => array( ... ),
    ),

    ...

field_data_commerce_line_items is a field created by commerce_order, which is another sub module in Commerce module during installation. You can find this behaviour here

commerce_order.module

/**
 * Implements hook_modules_enabled().
 */
function commerce_order_modules_enabled($modules) {
  commerce_order_configure_order_fields($modules);

  ...
}

/**
 * Ensures the line item field is present on the default order bundle.
 */
function commerce_order_configure_order_type($type = 'commerce_order') {
  // Look for or add a line item reference field to the order type.
  $field_name = 'commerce_line_items';
  commerce_activate_field($field_name);
  field_cache_clear();

  $field = field_info_field($field_name);
  $instance = field_info_instance('commerce_order', $field_name, $type);

  if (empty($field)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'commerce_line_item_reference',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'entity_types' => array('commerce_order'),
      'translatable' => FALSE,
      'locked' => TRUE,
    );
    $field = field_create_field($field);
  }

  ...

Please note that the field type here is commerce_line_item_reference, which is defined in commerce_line_item module as well.

commerce_line_item.install

/**
 * Implements hook_field_schema().
 */
function commerce_line_item_field_schema($field) {
  if ($field['type'] == 'commerce_line_item_reference') {
    return array(
      'columns' => array(
        'line_item_id' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
        ),
      ),
      'indexes' => array(
        'line_item_id' => array('line_item_id'),
      ),
      'foreign keys' => array(
        'line_item_id' => array(
          'table' => 'commerce_line_item',
          'columns' => array('line_item_id' => 'line_item_id'),
        ),
      ),
    );
  }
}

According to the schema defined above, commerce_line_item_reference acts exactly similar as a entity reference, which helps each order can be connected to a number of line items.

| improve this answer | |
  • I know it's a long time ago topic. But right now, I am a little confused that which table will actually store orders' information? – jmu Dec 21 '16 at 20:14
  • @jmu What kind of information you want from order? – Jimmy Ko Dec 22 '16 at 1:13
  • I think I got it. I want some detailed information. commerce_line_item is the table I need to look at. – jmu Dec 22 '16 at 15:18
  • @jmu cool. have a Merry Christmas! – Jimmy Ko Dec 22 '16 at 16:34
1

My answer concerns the structural and not the semantic difference between the two.

The table field_data_commerce_line_items corresponds to a standard drupal field. On the other hand commerce_line_item is a table that is managed by one of the modules in the commerce module family.

The table field_config_instance describes the relationships between drupal fields (which are actually tables such as field_data_commerce_line_items) and higher level entity types (i.e. node) and bundles (i.e. content type) that reference them.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.