diff -ur views/plugins/views_plugin_query_default.inc views_patched//plugins/views_plugin_query_default.inc --- views/plugins/views_plugin_query_default.inc 2011-08-10 18:29:10.179735475 +0300 +++ views_patched//plugins/views_plugin_query_default.inc 2011-08-10 18:28:37.111735488 +0300 @@ -130,7 +130,7 @@ // Utility methods to set flags and data. /** - * Set the base field to be distinct. + * Set the return set to be distinct. */ function set_distinct($value = TRUE) { if (!(isset($this->no_distinct) && $value)) { @@ -139,6 +139,15 @@ } /** + * Set distinct type. + */ + function set_distinct_type($value = TRUE) { + if (!(isset($this->no_distinct) && $value)) { + $this->distinct_type = $value; + } + } + + /** * Set what field the query will count() on for paging. */ function set_count_field($table, $field, $alias = NULL) { @@ -172,6 +181,10 @@ 'default' => FALSE, 'bool' => TRUE, ); + $options['distinct_type'] = array( + 'default' => 'base_field', + 'bool' => TRUE, + ); $options['slave'] = array( 'default' => FALSE, 'bool' => TRUE, @@ -207,6 +220,14 @@ '#description' => t('This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.'), '#default_value' => !empty($this->options['distinct']), ); + $form['distinct_type'] = array( + '#type' => 'select', + '#title' => t('Distinct criteria'), + '#description' => t('Choose criteria of what is distinct. Base field option will make result set unique by base field (e.g. nid, uid). Selected fields option will make result set unique by selected fields only.'), + '#options' => array('base_field' => t('Base field'), 'selected_field' => t('Selected fields only')), + '#default_value' => !empty($this->options['distinct_type']), + '#dependency' => array('edit-query-options-distinct' => array(TRUE)), + ); $form['slave'] = array( '#type' => 'checkbox', '#title' => t('Use Slave Server'), @@ -1140,8 +1161,10 @@ function query($get_count = FALSE) { // Check query distinct value. if (empty($this->no_distinct) && $this->distinct && !empty($this->fields)) { - $base_field_alias = $this->add_field($this->base_table, $this->base_field); - $this->add_groupby($base_field_alias); + if ($this->distinct_type == 'base_field') { + $base_field_alias = $this->add_field($this->base_table, $this->base_field); + $this->add_groupby($base_field_alias); + } $distinct = TRUE; } @@ -1279,6 +1302,10 @@ $this->set_distinct(); } + if (!empty($this->options['distinct_type'])) { + $this->set_distinct_type($this->options['distinct_type']); + } + // Store the view in the object to be able to use it later. $this->view = $view;