Hi there,
I'm writing a views handler where I join a table. Unfortunately, this does not work.
A short explanation (note that the module and the base table have the same names):
In mymodule_views_data():
$data['mybasetable]['table']['base'] = array('field' => 'uid',
'title' => 'my title',
'help' => 'my help'
);
?>
I want to join a (custom) user table. "mybasetable" has a uid field, and also the table i want to join has. My attempt to join in mymodile_views_data():
$data['mybasetable']['table']['join'] = array(
'myusertable' => array(
'left_table' => 'myusertable',
'left_field' => 'uid',
'field' => 'uid',
),
);
Now i want to have a field available in my view: "account", which is a field in "myusertable". Code in _data():
$data['mybasetable']['account'] = array(
'title' => t('Account-ID'),
'help' => t('Account-ID'),
'field' => array(
'handler' => 'views_handler_field_mybasetable_account',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_mybasetable_account',
),
'relationship' => array(
'base' => 'myusertable',
'field' => 'account',
'handler' => 'views_handler_relationship_mybasetable_account',
'label' => t('A Label'),
),
);
Now, in hook_handlers():
[..]
'views_handler_relationship_mybasetable_account' => array('parent' => 'views_handler_relationship'),
[..]
and finally in the handler file views_handler_relationship_mybasetable_account.inc:
class views_handler_relationship_mybasetable_account extends views_handler_relationship {
function construct() {
parent::construct();
}
}
When I clear all caches and preview the view (where the field "account" is added), I get:
user warning: Unknown column 'mybasetable.account' in 'field list' query: [...]
... and the joined table is missing in the query.
Does anyone have an idea?
Thanks a lot,
Stefan
Comments
Comment #1
dawehnerJust remove the relationship array line should fix the issue here. Views knows how your two tables are connected, so it can build the joins on the account fields for themselve