[development] D6 hook_views_data, external DB

Sean Dague sean at dague.net
Thu Mar 17 12:41:51 UTC 2011


I don't see a definition for the store_data table, just the definition 
for the relationship.  You'll have to define the store_data table as 
well, and the fields you are going to export to views, for you to be 
able to get anything reasonable out of that table.

I've got code in a sandbox project that does this kind of thing for 2 
custom tables if you are interested in looking at an example: 
http://drupalcode.org/sandbox/sdague/1072704.git/blob/refs/heads/6.x-1.x:/includes/lending.views.inc

I'm still a little new at this, so there might be better examples, but 
that works.

	-Sean

On 03/17/2011 07:53 AM, Wesley Nichols wrote:
> 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
>
>
>
>


-- 

Sean Dague                       Learn about the Universe with the
sean at dague dot net          Mid-Hudson Astronomical Association
http://dague.net                         http://midhudsonastro.org


More information about the development mailing list