Hi,
I appear to have a problem regarding a custom module that defines a hook_views_data() function.
I have two tables, external_news_articles (base table) and external_news_sites.
external_news_articles.sid links to external_new_sites.sid (primary key) but when I try and set any kind of basic view to pull data from both tables the resulting sql appears to be missing a field name.

See the 'LEFT JOIN' line (3rd) in the query below just after the ON statement - it is missing 'sid':

SELECT external_news_articles.aid AS aid, external_news_articles.sid AS external_news_articles_sid
FROM external_news_articles external_news_articles
LEFT JOIN external_news_sites external_news_sites ON external_news_articles. = external_news_sites.sid
INNER JOIN external_news_articles external_news_articles_external_news_sites ON external_news_sites.sid = external_news_articles_external_news_sites.aid

Here is the hook_views_data setup:

/**
 * Implementation of hook_views_data()
 */
function external_news_views_data() {
    $data = array(

        'external_news_articles' => array(
            // table
            'table' => array(
                'group' => t('Buzz Articles Group'),
                'base' => array(
                    'field' => 'aid',
                    'title' => t('Buzz Articles'),
                    'help' => t('Relation to external news articles'),
                ),
            ),
            // fields
            'aid' => array(
                'title' => t('article id'),
                'help' => t("id of each article"),
                'field' => array(
                    'handler' => 'views_handler_field',
                    'click sortable' => TRUE,
                ),
                'filter' => array(
                    'handler' => 'views_handler_filter_numeric',
                ),
            ),
            'sid' => array(
                'title' => t('linking site id'),
                'help' => t("id of each linked site"),
                'field' => array(
                    'handler' => 'views_handler_field',
                    'click sortable' => TRUE,
                ),
                'filter' => array(
                    'handler' => 'views_handler_filter_numeric',
                ),
            ),
        ),
        'external_news_sites' => array(
            // table
            'table' => array(
                'group' => t('Buzz Sites Group'),
                'join' => array(
                    'external_news_articles' => array(
                        // 'left-table' => 'external_news_sites',
                        'left-field' => 'sid',
                        'field' => 'sid',
                    ),
                ),
            ),
            // fields
            'sid' => array(
                'title' => t('linking site id'),
                'help' => t("id of each linked site"),
                'field' => array(
                    'handler' => 'views_handler_field',
                    'click sortable' => TRUE,
                ),
                'filter' => array(
                    'handler' => 'views_handler_filter_numeric',
                ),
                'relationship' => array(
                    'base' => 'external_news_articles',
                    'field' => 'sid',
                    'handler' => 'views_handler_relationship',
                    'label' => t('TESTER'),
                ),
            ),
            'site_name' => array(
                'title' => t('site name'),
                'help' => t("name of each linked site"),
                'field' => array(
                    'handler' => 'views_handler_field',
                    'click sortable' => TRUE,
                ),
                'filter' => array(
                    'handler' => 'views_handler_filter_string',
                ),
            ),
        ),
    );
    return $data;
}

Any help or pointers would be much appreciated.

Comments

T1ckL35’s picture

Hmmm, it appears that the 'left-field' statement in the join statement of external_news_views_data() doesn't appear to set the value in the sql query...

mustanggb’s picture

Status: Active » Closed (won't fix)