[icinga-checkins] icinga.org: icinga-web/r1.6: * Disable auto identifier feature for distinct queries

git at icinga.org git at icinga.org
Thu Dec 1 11:19:25 CET 2011


Module: icinga-web
Branch: r1.6
Commit: a954eea9cf319961bf7cd207a1c2ace3787afa0a
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=a954eea9cf319961bf7cd207a1c2ace3787afa0a

Author: Marius Hein <marius.hein at netways.de>
Date:   Thu Dec  1 11:16:24 2011 +0100

* Disable auto identifier feature for distinct queries

---

 .../lib/database/IcingaDoctrine_Query.class.php    |   22 ++++++++++++++++++-
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php b/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php
index 7057c7c..8ff3244 100644
--- a/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php
+++ b/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php
@@ -1,9 +1,16 @@
 <?php
 class IcingaDoctrine_Query extends Doctrine_Query {
     public static function create($conn = NULL, $class = NULL) {
-
         return new IcingaDoctrine_Query($conn);
     }
+    
+    /**
+     * To disable the hydrator fixing feature. In some cases it is needed
+     * to produce 'real' distinct queries
+     * @var boolean
+     */
+    protected $_disableAutoIdentifiedFields = false;
+    
     /**
     * @see Doctrine_Query::processPendingFields
     *
@@ -52,7 +59,7 @@ class IcingaDoctrine_Query extends Doctrine_Query {
             // only auto-add the primary key fields if this query object is not
             // a subquery of another query object or we're using a child of the Object Graph
             // hydrator
-            if (! $this->_isSubquery && is_subclass_of($driverClassName, 'Doctrine_Hydrator_Graph')) {
+            if (! $this->_isSubquery && is_subclass_of($driverClassName, 'Doctrine_Hydrator_Graph') && $this->_disableAutoIdentifiedFields == false) {
                 $fields = array_unique(array_merge((array) $table->getIdentifier(), $fields));
             }
         }
@@ -273,6 +280,17 @@ class IcingaDoctrine_Query extends Doctrine_Query {
         }
         return $this;
     }
+    
+    /**
+     * To produce real distinct query this function
+     * can disable to autoid feature
+     * @param boolean $flag
+     * @return IcingaDoctrine_Query
+     */
+    public function disableAutoIdentifierFields($flag) {
+        $this->_disableAutoIdentifiedFields = (boolean)$flag;
+        return $this;
+    }
 
 
 }





More information about the icinga-checkins mailing list