I have a block showing a view that is setup to show me a list of upcoming events. Many of these events are schedule on various dates such as Nov 3, Nov 10, Nov 17. The view shows the title and then all of the dates for that node because I have set "group multiple values" for the date field. It looks great but there is one problem. It shows a new entry in the list for each one of the dates. For example:

*
Living Arts Series: Saturdays @ MOCA
Sat, Nov 3, 2007 @ 1:00pm
Sat, Nov 17, 2007 @ 1:00pm
*
Experience Chinatown Walking Tours
Sat, Nov 3, 2007 @ 1:00pm
Sat, Nov 10, 2007 @ 1:00pm
Sat, Nov 17, 2007 @ 1:00pm
*
The Thunderstorm is Slowly Approaching by artist Qiu Zhijie
Sat, Nov 10, 2007 @ 12:00pm
*
Experience Chinatown Walking Tours
Sat, Nov 3, 2007 @ 1:00pm
Sat, Nov 10, 2007 @ 1:00pm
Sat, Nov 17, 2007 @ 1:00pm

You can see that the first two events show because of Nov 3 and then event 3 and 4 show because of the date Nov 10. But event 4 is the same node as event 2 - it should only show up once. I have even set a filter to that effect: Node: Distinct.

What's really interesting is that this only happens with I have set the list to sort on the date field. Otherwise it doesn't repeat (but then the list is in an unpredictable order).

I did some hunting around and I saw where the query was being executed in the views.module. It looks like this:

SELECT DISTINCT(node.nid), 
	node_data_field_date.field_date_value AS node_data_field_date_field_date_value, 
	node.title AS node_title, 
	node.changed AS node_changed 
FROM node node 
	LEFT JOIN content_field_date node_data_field_date ON node.vid = node_data_field_date.vid 
WHERE (node.type IN ('events')) 
	AND (( REPLACE(node_data_field_date.field_date_value2,'T',' ') + INTERVAL (-14400) SECOND) >= (NOW() + INTERVAL (-14400) SECOND)) 
GROUP BY 
	node_data_field_date_field_date_value,
	node.nid
ORDER BY node_data_field_date_field_date_value ASC 
LIMIT 0, 4

I see that the nid is qualified with DISTINCT. When I remove the 'node_data_field_date_field_date_value' field from the GROUP BY clause, it works. So now I am wondering how the 'node_data_field_date_field_date_value' got set in there?

Is there something I can set in the admin to overcome this issue? Is there something I can add to hook to override this behavior? I could add this code to views.module just after line 573, but I know that is the wrong way to go:

$query = str_replace('GROUP BY node.nid, node_data_field_date_field_date_value', 'GROUP BY node.nid', $query);

Below is an export of my view:

  $view = new stdClass();
  $view->name = 'hp_events';
  $view->description = 'Listing of events on hp.';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = FALSE;
  $view->page_title = '';x
  $view->page_header = '';
  $view->page_header_format = '4';
  $view->page_footer = '';
  $view->page_footer_format = '4';
  $view->page_empty = '';
  $view->page_empty_format = '4';
  $view->page_type = 'node';
  $view->url = '';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '10';
  $view->block = TRUE;
  $view->block_title = 'Home Page Events';
  $view->block_header = '';
  $view->block_header_format = '4';
  $view->block_footer = '';
  $view->block_footer_format = '4';
  $view->block_empty = '';
  $view->block_empty_format = '4';
  $view->block_type = 'list';
  $view->nodes_per_block = '4';
  $view->block_more = TRUE;
  $view->block_use_page_header = FALSE;
  $view->block_use_page_footer = FALSE;
  $view->block_use_page_empty = FALSE;
  $view->sort = array (
    array (
      'tablename' => 'node_data_field_date',
      'field' => 'field_date_value',
      'sortorder' => 'ASC',
      'options' => '',
    ),
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node_data_field_date',
      'field' => 'field_date_value',
      'label' => '',
      'handler' => 'content_views_field_handler_group',
      'options' => 'short',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'events',
),
    ),
    array (
      'tablename' => 'node_data_field_date',
      'field' => 'field_date_value_to|default',
      'operator' => '>=',
      'options' => '',
      'value' => 'now',
    ),
    array (
      'tablename' => 'node',
      'field' => 'distinct',
      'operator' => '=',
      'options' => '',
      'value' => array (
  0 => 'distinct',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node_data_field_date, node);
  $views[$view->name] = $view;

Comments

karens’s picture

Project: Date » Content Construction Kit (CCK)
Component: Code » Views Integration

This is a CCK issue and is a duplicate of http://drupal.org/node/140079

karens’s picture

Status: Active » Closed (duplicate)