6

I have a problem with my module views integration. I need to provide information about user who added video and timestamp. Video field is a CCK Embedded Media Field and it stores in content_field_3d_party_video table.

The schema is defined from the following code.

function MODULE_schema() {
  $schema = array();
  
  $schema['video_data'] = array(
      'description' => t('Users and timestamps for video field'),
      'fields' => array(
        'value' => array(
          'description' => t('Emfield value'),
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'default' => '',
        ),
        'uid' => array(
          'description' => t('User id'),
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'timestamp' => array(
          'description' => t('Timestamp'),
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array('value'),
      'indexes' => array(
        'timestamp' => array('timestamp'),
        'uid' => array('uid'),
      ),
    );
  
  return $schema;
}

The hook_views_data() implementation is the following.

function MODULE_views_data() {
  $data = array();
    
  $data['video_data']['table']['group'] = t('Video Data');
    
    $data['video_data']['table']['join'] = array(
        'node' => array(
            'left_table' => 'content_field_3d_party_video',
            'left_field' => 'field_3d_party_video_value',
            'field' => 'value',
        ),
        'users' => array(
            'left_field' => 'uid',
            'field' => 'uid',
        ),
    );
    
    $data['video_data']['value'] = array(
        'title' => t('Video value'),
        'relationship' => array(
            'base' => 'content_field_3d_party_video',
            'base field' => 'field_3d_party_video_value',
            'field' => 'value',
            'handler' => 'views_handler_relationship',
            'label' => t('Video value'),
        ),
    );

    $data['video_data']['uid'] = array(
        'title' => t('User id'),
        'relationship' => array(
            'base' => 'users',
            'base field' => 'uid',
            'field' => 'uid',
            'handler' => 'views_handler_relationship',
            'label' => t('User id'),
        ),
    );
    
    $data['video_data']['timestamp'] = array(
        'title' => t('Timestamp field'),
        'field' => array(
            'handler' => 'views_handler_field_date',
            'click sortable' => TRUE,
        ),
        'sort' => array(
            'handler' => 'views_handler_sort_date',
        ),
        'filter' => array(
            'handler' => 'views_handler_filter_date',
        ),
    );
    
    return $data;
}

The table isn't included in the SQL query generated for the view.

SELECT node.nid AS nid,
   node.title AS node_title,
   node.language AS node_language,
   node_data_field_3d_party_video.field_3d_party_video_embed AS node_data_field_3d_party_video_field_3d_party_video_embed,
   node_data_field_3d_party_video.field_3d_party_video_value AS node_data_field_3d_party_video_field_3d_party_video_value,
   ...
   node.type AS node_type,
   node.vid AS node_vid
 FROM node node 
 LEFT JOIN content_field_3d_party_video content_field_3d_party_video_video_data ON value = content_field_3d_party_video_video_data.field_3d_party_video_value
 LEFT JOIN users users_video_data ON uid = users_video_data.uid
 LEFT JOIN content_field_3d_party_video node_data_field_3d_party_video ON node.vid = node_data_field_3d_party_video.vid
 WHERE ...

May you help me?

apaderno
  • 28,547
  • 16
  • 75
  • 90
breethe
  • 613
  • 1
  • 6
  • 18
  • 3
    [It’s OK to Ask and Answer Your Own Questions](http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/) – Max Feb 19 '13 at 17:01

1 Answers1

0

This is the solution the OP previously posted in the question.

To correctly join the table used for a CCK field, we must specify node_data_field_3d_party_video as left_table, instead of content_field_3d_party_video.

$data['video_data']['table']['join'] = array(
    'node' => array(
        'left_table' => 'node_data_field_3d_party_video',
        'left_field' => 'field_3d_party_video_value',
        'field' => 'value',
    ),
    'users' => array(
        'left table' => 'users',
        'left_field' => 'uid',
        'field' => 'uid',
    ),
);
apaderno
  • 28,547
  • 16
  • 75
  • 90
progzy
  • 607
  • 1
  • 4
  • 5