Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
removed "Drupal" and tags from the title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Drupal 7 Views Custom Join injoin with an External Databaseexternal database

I am trying to join two tables in a second database (they are both inon the same database, db2). I am trying to join tablenametablename to tablename2 ontablename2 using the field tablename.ItemID = tablename2.ItemIDcondition tablename.ItemID = tablename2.ItemID. While the values from tablename onetablename are selectable in viewsfrom a view, those from tablename2 are not appearingtablename2 aren't. Am I missing something, do

Do I need to specify in what database tablename2 is in?

<?php

/** 
* Implementation of hook_views_data
*/

function  mydatabase_views_views_data() {
    error_log("Loading views");
    $data['tablename']['table']['group'] = t('Title name');
    $data['tablename']['table']['base'] = array(
       'field' => 'ItemID',
       'title' => t('db2'),
       'help' => t('Autoincremented ID field, to enable views integration'),
       'database' => 'db2',
       'weight' => -10,
    );

    $data['tablename']['table']['join'] = array(
        'deals_addon' => array(
            'left_field' => 'ItemID',
            'field' => 'ItemID',
        ),
    );

    $data['tablename']['ItemID'] = array(
         'title' => t('Item ID'),
         'help' => t('Item ID'),
         'field' => array(
               'handler' => 'views_handler_field',
               'click sortable' => TRUE,
          ),
          'sort' => array(
                'handler' => 'views_handler_sort',
          ),
          'filter' => array(
                'handler' => 'views_handler_filter_string',
          ),
          'argument' => array(
                'handler' => 'views_handler_argument_string',
          ),
    );

    $data['tablename']['ItemInfo'] = array(
         'title' => t('Item Info'),
         'help' => t('Item Info'),
         'relationship' => array(
             'base' => 'tablename2',
             'base_field' => 'ItemID',
             'handler' => 'views_handler_relationship',
             'label' => t('Label'),
             'title' => t('Title'),
             'help' => t('Help'),
        ),
    );
    return $data;  
}
/** 
* Implementation of hook_views_data
*/

function  mydatabase_views_views_data() {
  $data['tablename']['table']['group'] = t('Title name');
  $data['tablename']['table']['base'] = array(
    'field' => 'ItemID',
    'title' => t('db2'),
    'help' => t('Autoincremented ID field, to enable views integration'),
    'database' => 'db2',
    'weight' => -10,
  );

  $data['tablename']['table']['join'] = array(
    'deals_addon' => array(
      'left_field' => 'ItemID',
      'field' => 'ItemID',
    ),
  );

  $data['tablename']['ItemID'] = array(
    'title' => t('Item ID'),
    'help' => t('Item ID'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['tablename']['ItemInfo'] = array(
    'title' => t('Item Info'),
    'help' => t('Item Info'),
    'relationship' => array(
      'base' => 'tablename2',
      'base_field' => 'ItemID',
      'handler' => 'views_handler_relationship',
      'label' => t('Label'),
      'title' => t('Title'),
      'help' => t('Help'),
    ),
  );
  return $data;  
}

Drupal 7 Views Custom Join in an External Database

I am trying to join two tables in a second database (they are both in the same database, db2). I am trying to join tablename to tablename2 on the field tablename.ItemID = tablename2.ItemID. While the values from tablename one are selectable in views, those from tablename2 are not appearing. Am I missing something, do I need to specify what database tablename2 is in?

<?php

/** 
* Implementation of hook_views_data
*/

function  mydatabase_views_views_data() {
    error_log("Loading views");
    $data['tablename']['table']['group'] = t('Title name');
    $data['tablename']['table']['base'] = array(
       'field' => 'ItemID',
       'title' => t('db2'),
       'help' => t('Autoincremented ID field, to enable views integration'),
       'database' => 'db2',
       'weight' => -10,
    );

    $data['tablename']['table']['join'] = array(
        'deals_addon' => array(
            'left_field' => 'ItemID',
            'field' => 'ItemID',
        ),
    );

    $data['tablename']['ItemID'] = array(
         'title' => t('Item ID'),
         'help' => t('Item ID'),
         'field' => array(
               'handler' => 'views_handler_field',
               'click sortable' => TRUE,
          ),
          'sort' => array(
                'handler' => 'views_handler_sort',
          ),
          'filter' => array(
                'handler' => 'views_handler_filter_string',
          ),
          'argument' => array(
                'handler' => 'views_handler_argument_string',
          ),
    );

    $data['tablename']['ItemInfo'] = array(
         'title' => t('Item Info'),
         'help' => t('Item Info'),
         'relationship' => array(
             'base' => 'tablename2',
             'base_field' => 'ItemID',
             'handler' => 'views_handler_relationship',
             'label' => t('Label'),
             'title' => t('Title'),
             'help' => t('Help'),
        ),
    );
    return $data;  
}

Custom join with an external database

I am trying to join two tables on the same database, db2. I am trying to join tablename to tablename2 using the condition tablename.ItemID = tablename2.ItemID. While the values from tablename are selectable from a view, those from tablename2 aren't.

Do I need to specify in what database tablename2 is?

/** 
* Implementation of hook_views_data
*/

function  mydatabase_views_views_data() {
  $data['tablename']['table']['group'] = t('Title name');
  $data['tablename']['table']['base'] = array(
    'field' => 'ItemID',
    'title' => t('db2'),
    'help' => t('Autoincremented ID field, to enable views integration'),
    'database' => 'db2',
    'weight' => -10,
  );

  $data['tablename']['table']['join'] = array(
    'deals_addon' => array(
      'left_field' => 'ItemID',
      'field' => 'ItemID',
    ),
  );

  $data['tablename']['ItemID'] = array(
    'title' => t('Item ID'),
    'help' => t('Item ID'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['tablename']['ItemInfo'] = array(
    'title' => t('Item Info'),
    'help' => t('Item Info'),
    'relationship' => array(
      'base' => 'tablename2',
      'base_field' => 'ItemID',
      'handler' => 'views_handler_relationship',
      'label' => t('Label'),
      'title' => t('Title'),
      'help' => t('Help'),
    ),
  );
  return $data;  
}
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Source Link
John
  • 215
  • 2
  • 9

Drupal 7 Views Custom Join in an External Database

I am trying to join two tables in a second database (they are both in the same database, db2). I am trying to join tablename to tablename2 on the field tablename.ItemID = tablename2.ItemID. While the values from tablename one are selectable in views, those from tablename2 are not appearing. Am I missing something, do I need to specify what database tablename2 is in?

<?php

/** 
* Implementation of hook_views_data
*/

function  mydatabase_views_views_data() {
    error_log("Loading views");
    $data['tablename']['table']['group'] = t('Title name');
    $data['tablename']['table']['base'] = array(
       'field' => 'ItemID',
       'title' => t('db2'),
       'help' => t('Autoincremented ID field, to enable views integration'),
       'database' => 'db2',
       'weight' => -10,
    );

    $data['tablename']['table']['join'] = array(
        'deals_addon' => array(
            'left_field' => 'ItemID',
            'field' => 'ItemID',
        ),
    );

    $data['tablename']['ItemID'] = array(
         'title' => t('Item ID'),
         'help' => t('Item ID'),
         'field' => array(
               'handler' => 'views_handler_field',
               'click sortable' => TRUE,
          ),
          'sort' => array(
                'handler' => 'views_handler_sort',
          ),
          'filter' => array(
                'handler' => 'views_handler_filter_string',
          ),
          'argument' => array(
                'handler' => 'views_handler_argument_string',
          ),
    );

    $data['tablename']['ItemInfo'] = array(
         'title' => t('Item Info'),
         'help' => t('Item Info'),
         'relationship' => array(
             'base' => 'tablename2',
             'base_field' => 'ItemID',
             'handler' => 'views_handler_relationship',
             'label' => t('Label'),
             'title' => t('Title'),
             'help' => t('Help'),
        ),
    );
    return $data;  
}