Accessing an external database: Views not finding nid

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
kwfinken's picture

I am attempting to link the views module to an external database. I have placed the following in hoursdb.module and have an associated hoursdb.info file. When I create a new view, an error appears saying SQLSTATE[42S22]: Column not found: 1054 Unknown column 'times.nid' in 'field list'. (The attached image shows the SQL that the views module generated and the error.) What is views looking for and how do I either give it to views or get views to stop asking for it?

I did try adding a "fake" field in the module listing but that didn't work.

BTW, I don't have access to add any fields to the external database.

<?php

/
* @file
* Exposes the hours database to be used in a view.
*/

/

* Implements hook_views_data()
*/
function hoursdb_views_data() {
   $data = array(
      'times' => array(
        // ...info about the table named 'times'...
        'table' => array(
          'group' => t('MSUL: Hours'),
          'base' => array (
            'field' => 'id',
            'title' => 'hoursdb_hours',
            'database' => 'hours_db',
          ),
          'join' => array(
            'units' => array(
              'left_field' => 'id',
              'field' => 'unit_id',
            ),
          ),
        ),
        'date' => array(
          'title' => t('Date'),
          'help' => t('date to which these hours apply'),
          'field' => array(
            'handler' => 'views_handler_field_date',
            'click sortable' => TRUE,
          ),
          'filter' => array(
            'handler' => 'views_handler_filter_date'
          ),
          'sort' => array(
            'handler' => 'views_handler_sort'
          ),
        ),
        'time_start' => array(
          'title' => t('Start Time'),
          'help' => t('time the unit opens for the day'),
          'field' => array(
            'handler' => 'views_handler_field_date',
          ),
        ),
        'time_end' => array(
          'title' => t('End Time'),
          'help' => t('time the unit closes for the day'),
          'field' => array(
            'handler' => 'views_handler_field_date',
          ),
        ),
        'closed_time_start' => array(
          'title' => t('Closed Start Time'),
          'help' => t('optional time the unit closes temporarily (e.g. lunch)'),
          'field' => array(
            'handler' => 'views_handler_field_date',
          ),
        ),
        'closed_time_end' => array(
          'title' => t('Closed End Time'),
          'help' => t('optional time the unit re-opens (e.g. after lunch)'),
          'field' => array(
            'handler' => 'views_handler_field_date',
          ),
        ),
        'approved' => array(
          'title' => t('Approved Date/Time'),
          'help' => t('When this item was approved.  Latest approval wins.'),
          'field' => array(
            'handler' => 'views_handler_field_date',
            'click sortable' => TRUE,
          ),
          'filter' => array(
            'handler' => 'views_handler_filter_date'
          ),
          'sort' => array(
            'handler' => 'views_handler_sort'
          ),
        ),
        'unit_id' => array(
          'title' => t('Unit Reference'),
          'help' => t('reference to Unit that these hours apply to'),
          'field' => array(
            'handler' => 'views_handler_field_date',
          ),
          'sort' => array(
            'handler' => 'views_handler_sort'
          ),
        ),
        'tba' => array(
          'title' => t('Hours TBA'),
          'help' => t('if true, indicates that the hours are not yet set for the day'),
          'field' => array(
            'handler' => 'views_handler_field_boolean',
          ),
        ),
      ),

     'units' => array(
        // ...info about the table named 'units'...
        'table' => array(
          'group' => t('MSUL: Hours'),
          'base' => array (
            'field' => 'id',
            'title' => 'hoursdb_units',
            'database' => 'hours_db',
          ),
          'join' => array(
            'times' => array(
              'left_field' => 'unit_id',
              'field' => 'id',
            ),
          ),
        ),
      ),
    );
    return $data;
}
AttachmentSize
Views Error - unknown column nid.jpg89.1 KB

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: