Changeset 5326

Show
Ignore:
Timestamp:
12/31/08 20:24:07 (6 months ago)
Author:
guilhermeblanco
Message:

fixes #1772. Thanks for the patch! I had to modify it a little, because it was breaking 2 test cases in our test suite.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/lib/Doctrine/Query/Having.php

    r4888 r5326  
    5959 
    6060        } else { 
    61             if ( ! is_numeric($func)) { 
    62                 $a = explode('.', $func); 
    63  
    64                 if (count($a) > 1) { 
    65                     $field     = array_pop($a); 
    66                     $reference = implode('.', $a); 
    67                     $map       = $this->query->load($reference, false); 
    68                     $field     = $map['table']->getColumnName($field); 
    69                     $func      = $this->query->getTableAlias($reference) . '.' . $field; 
    70                 } else { 
    71                     $field = end($a); 
    72                     $func  = $this->query->getAggregateAlias($field); 
    73                 } 
    74                 return $this->query->getConnection()->quoteIdentifier($func); 
    75             } else { 
    76                 return $this->query->getConnection()->quoteIdentifier($func); 
    77             } 
     61            return $this->_parseAliases($func); 
    7862        } 
    7963    } 
    8064 
     65    /** 
     66     * _parseAliases 
     67     * Processes part of the query not being an aggregate function 
     68     * 
     69     * @param mixed $value 
     70     * @return string 
     71     */ 
     72    final private function _parseAliases($value) 
     73    { 
     74        if ( ! is_numeric($value)) { 
     75            $a = explode('.', $value); 
     76 
     77            if (count($a) > 1) { 
     78                $field = array_pop($a); 
     79                $ref   = implode('.', $a); 
     80                $map   = $this->query->load($ref, false); 
     81                $field = $map['table']->getColumnName($field); 
     82                $value = $this->query->getTableAlias($ref) . '.' . $field; 
     83            } else { 
     84                $field = end($a); 
     85                $value = $this->query->getAggregateAlias($field); 
     86            } 
     87             
     88            return $this->query->getConnection()->quoteIdentifier($value); 
     89        } 
     90         
     91         
     92        return $value; 
     93    } 
    8194 
    8295    /** 
     
    93106        $operator  = array_shift($tokens); 
    94107        $value     = implode(' ', $tokens); 
    95         $part .= ' ' . $operator . ' ' . $value; 
     108 
    96109        // check the RHS for aggregate functions 
    97110        if (strpos($value, '(') !== false) { 
    98111          $value = $this->parseAggregateFunction($value); 
    99112        } 
     113 
     114        $part .= ' ' . $operator . ' ' . $value; 
     115 
    100116        return $part; 
    101117    }