Views 1: how to sort on fields from 2 tables?
I'm working on a D5 site (yes, unfortunately!) where we use taxonomy to create a "poor-man's-epublish" - basically a view of newsletter issues and articles under them. We have a vocabulary for "Newsletter issue" and just tag article nodes with the term of the issue, like "Fall 2008." Since there are other vocabularies on those nodes we're using the primary_term module to make the newletter issue the primary term.
It's all working great except for sorting: primary_term.module only implements views sorting by term id - it ignores the term weight:
function primary_term_views_tables() {
$tables['primary_term'] = array(
'name' => 'primary_term',
'join' => array('left' => array('table' => 'node', 'field' => 'vid'),
'right' => array('field' => 'vid')),
'fields' => array(
'tid' => array(
'name' => t('Primary Term'),
'handler' => 'primary_term_views_handler_field_tid',
'addlfields' => array('tid'),
'help' => t('This will display the name of the Primary Term of the node.'),
),
),
'sorts' => array(
'tid' => array(
'name' => t('Primary Term'),
),
),
'filters' => array(
'tid' => array(
'name' => t('Primary Term'),
'operator' => 'views_handler_operator_andor',
'list' => 'views_handler_filter_tid',
'value-type' => 'array',
'help' => t('Filter by the node\'s Primary Term.'),
)
)
);
return $tables;
}Sorting by term ID seems really unhelpful. What we need is the same sort as Views' built-in taxonomy support: term weight, then term name:
'sorts' => array(
'weight' => array(
'name' => t('Taxonomy: Term Name'),
'field' => array('weight', 'name'),
'help' => t('This will sort nodes by taxonomy weight and name, as defined in the category administration.'),
)
),I want to patch primary_term.module to change the sort. It seems clear I need to make a join between primary_term and term_data, but I can't figure out how to specify to Views to sort on fields that come from 2 different tables in a join.
I've read over the <a href="http://drupal.org/node/99793>relevant page in the Views 1 API guide, but still can't figure it out. If Views 1 isn't too ancient a topic, I would appreciate any help!
(Alternatively, if anyone knows a sure-fire way to make Views always use a specific vocabulary for filtering and sorting, we could dispense with the primary_term module entirely. I'm using it because I couldn't reliably get Views to always use that vocabulary, even with fooling with the Vocabulary weight etc.)

