The following is a cut-down definition of the problem. I have pared it back to the bare minimum for example purposes.
I am using CCK 6.x-2.1 and Date 6.x-2.0-rc6 with Views 6.x-2.2. The problem occurs on a Drupal 6.9 system, and also on a localhost Drupal 6.5 system.
I have two content types defined.
- a "meeting", which contains a CCK date field (text field with popup calendar) to set the date of the meeting.
- an "agenda", which contains a CCK nodereference field to link it to the "meeting". (there are other content types similar to "agenda" which also link back to "meeting" but these two will suffice to demonstrate the problem).
I require a view that lists all meeting component content types ("meeting" and "agenda" in this example), and to show the date of the meeting against each node listed.
Ideally I would like one date field column that displayed the date value as determined by content type, but I think that is not possible. So I opted for two columns, the first being the CCK date field taken directly from the "meeting" content type, and the second being a date field for the "agenda" content type, derived via a relationship back to the linked "meeting" node. I can accept that one column will be blank when the other contains a date value.
I have found that if I list the meeting date first for "meetings" in the views field order, followed by the derived meeting date for "agenda", I only get the "meeting" date shown, but it appears in both columns! If I reverse the order of the fields displayed, so that derived meeting date for "agenda" is above "meeting" date in the fields position display, I now get the derived meeting date value only for "agenda", but again in both columns!
Can anyone please tell me if this is a fault in CCK/Views or just a restriction that I must live with?
To prove this example, I have gone to a new Drupal installation, generated two content types as defined above, with the appropriate CCK fields, and then added one node for each type, with the agenda node referencing the meeting node. I then generated a single view, and can see in the preview the effect explained above, simply by reversing the order of the date fields.
Here is the views export with the "meeting" date field first and the derived date field for "agenda" second.
$view = new view;
$view->name = 'meetings';
$view->description = 'Meetings';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Meetings', 'default');
$handler->override_option('relationships', array(
'field_meeting_nid' => array(
'label' => 'Meeting',
'required' => 0,
'delta' => -1,
'id' => 'field_meeting_nid',
'table' => 'node_data_field_meeting',
'field' => 'field_meeting_nid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'type' => array(
'label' => 'Type',
'link_to_node' => 0,
'exclude' => 0,
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'title' => array(
'label' => 'Title',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'field_date_value' => array(
'label' => 'Meeting Date',
'link_to_node' => 1,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_date_value',
'table' => 'node_data_field_date',
'field' => 'field_date_value',
'relationship' => 'field_meeting_nid',
),
'field_date_value_1' => array(
'label' => 'Meeting Date',
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_date_value_1',
'table' => 'node_data_field_date',
'field' => 'field_date_value',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'field_meeting_nid' => array(
'id' => 'field_meeting_nid',
'table' => 'node_data_field_meeting',
'field' => 'field_meeting_nid',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'agenda' => 'agenda',
'meeting' => 'meeting',
),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'type_op',
'identifier' => 'type',
'label' => 'Type',
'optional' => 1,
'single' => 1,
'remember' => 0,
'reduce' => 1,
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'role',
'role' => array(
'3' => 3,
),
));
$handler->override_option('title', 'Default');
$handler->override_option('empty', 'No meetings to display');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 1,
'order' => 'asc',
'columns' => array(
'type' => 'type',
'title' => 'title',
'field_date_value' => 'field_date_value',
'field_date_value_1' => 'field_date_value_1',
'name_1' => 'name_1',
'changed' => 'changed',
'name' => 'name',
),
'info' => array(
'type' => array(
'sortable' => 1,
'separator' => '',
),
'title' => array(
'sortable' => 1,
'separator' => '',
),
'field_date_value' => array(
'sortable' => 1,
'separator' => '',
),
'field_date_value_1' => array(
'sortable' => 1,
'separator' => '',
),
'name_1' => array(
'sortable' => 1,
'separator' => '',
),
'changed' => array(
'sortable' => 1,
'separator' => '',
),
'name' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => 'title',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'meetings');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
And here is the SQL executed on the live preview
SELECT node.nid AS nid,
node.type AS node_type,
node.title AS node_title,
node_data_field_date.field_date_value AS node_data_field_date_field_date_value,
node_data_field_date.nid AS node_data_field_date_nid,
node_node_data_field_meeting.type AS node_node_data_field_meeting_type
FROM node node
LEFT JOIN content_type_agenda node_data_field_meeting ON node.vid = node_data_field_meeting.vid
LEFT JOIN node node_node_data_field_meeting ON node_data_field_meeting.field_meeting_nid = node_node_data_field_meeting.nid
LEFT JOIN content_type_meeting node_data_field_date ON node.vid = node_data_field_date.vid
WHERE node.type in ('agenda', 'meeting')
ORDER BY node_title ASC
This is what the preview contains with meeting date field first in the fields list
Type Title date date
meeting This is a meeting 09 Feb 09 09 Feb 09
agenda This is an agenda
..and with the fields reversed....
Type Title date date
meeting This is a meeting
agenda This is an agenda 09 Feb 09 09 Feb 09