use group by to ensure row count correctness in any case.
authorDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Tue, 4 Mar 2014 14:26:13 +0000 (19:56 +0530)
committerDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Tue, 4 Mar 2014 14:26:13 +0000 (19:56 +0530)
CRM/Contribute/BAO/Query.php
CRM/Contribute/Selector/Search.php

index 43920394a517e348184816edd93f7b4a42199a5f..092726307c763ba70afcb7024230e5f6834f4ed8 100644 (file)
@@ -368,13 +368,16 @@ class CRM_Contribute_BAO_Query {
         if ($value == 'only_scredits') {
           $query->_where[$grouping][] = "contribution_search_scredit_combined.scredit_id IS NOT NULL";
           $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Soft Credits Only');
+          $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
           $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
         } else if ($value == 'both_related') {
           $query->_where[$grouping][] = "contribution_search_scredit_combined.filter_id IS NOT NULL";
           $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Both But Related');
+          $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
           $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
         } else if ($value == 'both') {
           $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Both');
+          $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
           $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
         }
         // default option: $value == 'only_contribs'
@@ -780,8 +783,9 @@ class CRM_Contribute_BAO_Query {
   static function initializeAnySoftCreditClause(&$query) {
     if (self::isSoftCreditOptionEnabled($query->_params)) {
       if ($query->_mode & CRM_Contact_BAO_Query::MODE_CONTRIBUTE) {
-        unset($query->_distinctComponentClause, $query->_groupByComponentClause);
+        unset($query->_distinctComponentClause);
         $query->_rowCountClause = " count(civicrm_contribution.id)";
+        $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
       }
     }
   }
index cb17eef2fe0bcd296b6f498109c4bbe0a6955127..1301561e425a2f27fb5a8ee4ff7b15728243045c 100644 (file)
@@ -200,6 +200,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
     );
     if ($this->_includeSoftCredits) {
       $this->_query->_rowCountClause = " count(civicrm_contribution.id)";
+      $this->_query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
     } else {
       $this->_query->_distinctComponentClause = " civicrm_contribution.id";
       $this->_query->_groupByComponentClause = " GROUP BY civicrm_contribution.id ";