Commit 319b645d authored by zYne's avatar zYne

Fixes #221

parent bd776a68
...@@ -187,31 +187,36 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -187,31 +187,36 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
/** /**
* count * count
* *
* @param array $params
* @return integer * @return integer
*/ */
public function count(Doctrine_Table $table, $params = array()) { public function count($params = array()) {
$this->remove('select'); $this->remove('select');
$join = $this->join; $join = $this->join;
$where = $this->where; $where = $this->where;
$having = $this->having; $having = $this->having;
$table = reset($this->tables);
$q = 'SELECT COUNT(DISTINCT ' . $this->getShortAlias($table->getTableName())
. '.' . $table->getIdentifier()
. ') FROM ' . $table->getTableName() . ' ' . $this->getShortAlias($table->getTableName);
$q = "SELECT COUNT(DISTINCT ".$table->getTableName().'.'.$table->getIdentifier().") FROM ".$table->getTableName()." ";
foreach($join as $j) { foreach($join as $j) {
$q .= ' '.implode(" ",$j); $q .= ' '.implode(' ',$j);
} }
$string = $this->applyInheritance(); $string = $this->applyInheritance();
if( ! empty($where)) { if( ! empty($where)) {
$q .= " WHERE ".implode(" AND ",$where); $q .= ' WHERE ' . implode(' AND ', $where);
if( ! empty($string)) if( ! empty($string))
$q .= " AND (".$string.")"; $q .= ' AND (' . $string . ')';
} else { } else {
if( ! empty($string)) if( ! empty($string))
$q .= " WHERE (".$string.")"; $q .= ' WHERE (' . $string . ')';
} }
if( ! empty($having)) if( ! empty($having))
$q .= " HAVING ".implode(' AND ',$having); $q .= ' HAVING ' . implode(' AND ',$having);
$a = $this->getConnection()->execute($q, $params)->fetch(PDO::FETCH_NUM); $a = $this->getConnection()->execute($q, $params)->fetch(PDO::FETCH_NUM);
return $a[0]; return $a[0];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment