Fixes #221
This commit is contained in:
parent
bd776a680a
commit
319b645daa
@ -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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user