Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
7 Feb 2011 at 07:48 UTC
Updated:
11 Apr 2011 at 01:01 UTC
I created an attachment containing one field, user:name, and checked Distinct. The query does not contain the DISTINCT keyword, and the results reflect that.
I see other issues regarding distinct, but they appear to be other errors regarding it, or different versions of Views, or both.
Comments
Comment #1
dawehnerIf you look at the result of the query a groupby NID is added.
See #863478: Distinct is not supported by dbtng
Comment #2
j. ayen green commentedSo, with this one:
1. I clone the glossary view
2. Create an attachment display (this is then the second attachment)
3. The attachment has one field (user:name), no arguments, no filters, sort criteria of user:name ascending, and query settings set to distinct
4. The sql result is:
SELECT users.name AS users_name
FROM
{node} node
INNER JOIN {users} users ON node.uid = users.uid
ORDER BY users_name ASC
LIMIT 10 OFFSET 0
5. and the display is
Author
ayen
ayen
ayen
ayen
ayen
ayen
ayen
ayen
ayen
ayen
Comment #3
j. ayen green commentedBelow is the export of the additional attachment display. Again, the idea is that the second attachment will provide a list of all authors. The problem is that no permutation of Group By setting and Query Setting: Distinct results in each author name being displayed once, rather than once for every node (in other words, if there are 4 nodes, 2 each for 2 authors, the resulting list has four rows).
/* Display: Attachment */
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
$handler->display->display_options['defaults']['query'] = FALSE;
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['grouping'] = 'name';
$handler->display->display_options['style_options']['columns'] = array(
'name' => 'name',
);
$handler->display->display_options['style_options']['default'] = 'name';
$handler->display->display_options['style_options']['info'] = array(
'name' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
),
);
$handler->display->display_options['style_options']['override'] = 0;
$handler->display->display_options['style_options']['sticky'] = 0;
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = 'Author';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['name']['alter']['path'] = 'author-glossary/all/[name]';
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['link_to_user'] = 0;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
$handler->display->display_options['defaults']['sorts'] = FALSE;
/* Sort criterion: User: Name */
$handler->display->display_options['sorts']['name']['id'] = 'name';
$handler->display->display_options['sorts']['name']['table'] = 'users';
$handler->display->display_options['sorts']['name']['field'] = 'name';
$handler->display->display_options['defaults']['arguments'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
$handler->display->display_options['attachment_position'] = 'after';
$handler->display->display_options['inherit_arguments'] = 0;
$handler->display->display_options['displays'] = array(
'page' => 'page',
'default' => 0,
);
Comment #4
j. ayen green commentedI did try another view, and group by nid was present in the query...do not know why it's not in the one above. But that said, I don't understand the intent. If I have one field being displayed, let's say publish date, if I only want one occurrence of each date to be listed, I would choose Distinct, so that the query would be "SELECT DISTINCT publish_date..." I don't see how not having distinct but having Group by nid would be useful.
Comment #5
j. ayen green commentedWill do.
Comment #6
merlinofchaos commentedChecked in a fix to set $query->distinct() when we're supposed to actually be distinct.