[development] D6 hook_views_data, external DB

Wesley Nichols spanishwes at gmail.com
Thu Mar 17 11:53:36 UTC 2011


Hi Drupalistas,

A little stumped on describing my tables to views in D6.  Specifically,
I can't figure out how to join tables correctly.  I am querying an
external database and I can retrieve info from the base table, but I
can't get the join to pull data from the joined table.

2 tables: client_data, store_data

I am trying to join the tables on the 'store_id' key

Currently, for my implementation of hook_views_data() I have:
  // Set group
  $data['client_data']['table']['group']  = t('CC Clients');
  // Define base table
  $data['client_data']['table']['base'] = array(
    'field' => 'client_id',
    'title' => t('CC Clients'),
    'help' => t("View displays CC Clients."),
    'database' => 'cc',
  );
  // Define table join
  $data['client_data']['table']['join'] = array(
    'store_data' => array(
      //Joined table key
      'left_field' => 'store_id',
      'field' => 'store_id',
    ),
  );
  //Numeric
  $data['client_data']['client_id'] = array(
    'title' => t('Client ID'),
    'help' => t('The numeric ID of the Client'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'numeric' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  // Store Name (from join)
  $data['client_data']['store_name'] = array(
    'title' => t('Store Name'),
    'help' => t('Returns Store Name for a Store ID associated with a
Client'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'relationship' => array(
      'title' => t('Store Name'),
      'help' => t('The Store Name where registered.'),
      'base' => 'store_data',
      'base field' => 'store_id',
      'handler' => 'views_handler_relationship',
      'label' => t('Store Name'),
    ),
  );


Expected result is: Client ID: 1, Store Name: MyStore #5
Actual result is: Client ID:1, Store Name: 5

No join takes place.

Any suggestions appreciated,
Thanks!

Wes Nichols






More information about the development mailing list