/**
  * @param $filter
  */
 protected function gallery($filter)
 {
     if (!$this->_gallery_added) {
         $this->_query->leftJoin('f.Slices s');
         $this->_query->groupBy('f.id');
         $this->_gallery_added = true;
     }
     switch ($filter->operator) {
         case 'is':
             $s = $this->_slice_alias_count++;
             $this->_query->andWhere('f.id in (SELECT s' . $s . '.file_id FROM RokGallery_Model_Slice s' . $s . ' where s' . $s . '.gallery_id = ? GROUP BY s' . $s . '.file_id)', $filter->query);
             $this->_query->andWhere('s.gallery_id = ?', $filter->query);
             break;
         default:
     }
 }
 /**
  * Retrieves tags with the number of taggings for a given set of models, can be accessed using ->$model
  *
  * @param Array $models
  * @param Doctrine_Query $q
  * @return Doctrine_Query
  */
 public function queryTagsWithCountsByModel($models, $q = null)
 {
     $q->leftJoin('r.Tagging tg')->addSelect('r.*');
     foreach ($models as $model) {
         $q->addSelect("SUM(IF(tg.taggable_model = '{$model}' , 1, 0)) AS " . $model . "Count");
     }
     $q->groupBy('r.id');
     return $q;
 }
 public function testCountWithGroupBy()
 {
     $q = new Doctrine_Query();
     $q->from('User u');
     $q->leftJoin('u.Phonenumber p');
     $q->groupBy('p.entity_id');
     $this->assertEqual($q->count(), $q->execute()->count());
 }