diff --git a/Doctrine/Query.php b/Doctrine/Query.php index 2a6846db3..dac76915b 100644 --- a/Doctrine/Query.php +++ b/Doctrine/Query.php @@ -38,11 +38,11 @@ class Doctrine_Query extends Doctrine_Hydrate { $where = $this->where; $having = $this->having; - $q = "SELECT COUNT(1) FROM ".$table." "; + $q = "SELECT COUNT(1) FROM ".$table->getComponentName()." "; foreach($join as $j) { $q .= implode(" ",$j); } - $string = $query->applyInheritance(); + $string = $this->applyInheritance(); if( ! empty($where)) { $q .= " WHERE ".implode(" AND ",$where); @@ -56,7 +56,7 @@ class Doctrine_Query extends Doctrine_Hydrate { if( ! empty($having)) $q .= " HAVING ".implode(' AND ',$having); - $a = $this->table->getSession()->execute($q, $params)->fetch(PDO::FETCH_NUM); + $a = $this->getSession()->execute($q, $params)->fetch(PDO::FETCH_NUM); return $a[0]; } /** diff --git a/Doctrine/Table.php b/Doctrine/Table.php index dafdd0299..2e3a4c6bb 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -398,7 +398,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { */ final public function getBound($name) { if( ! isset($this->bound[$name])) - throw new InvalidKeyException(); + throw new InvalidKeyException('Unknown bound '.$name); return $this->bound[$name]; } @@ -414,7 +414,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { return $this->bound[$k]; } } - throw new InvalidKeyException(); + throw new InvalidKeyException('Unknown bound '.$name); } /** * returns the alias for given component name @@ -438,7 +438,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { if($name = array_search($this->boundAliases,$alias)) return $name; - throw new InvalidKeyException(); + throw new InvalidKeyException('Unknown alias '.$alias); } /** * unbinds all relations @@ -480,7 +480,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { */ final public function bind($name,$field,$type,$localKey) { if(isset($this->relations[$name])) - throw new InvalidKeyException(); + throw new InvalidKeyException('Relation already set for '.$name); $e = explode(" as ",$name); $name = $e[0]; @@ -540,6 +540,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * @return Doctrine_Relation */ final public function getForeignKey($name) { + $original = $name; + if(isset($this->relations[$name])) return $this->relations[$name]; @@ -614,7 +616,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $this->relations[$alias] = $relation; return $this->relations[$alias]; } - throw new InvalidKeyException(); + throw new InvalidKeyException('Unknown relation '.$original); } /** * returns an array containing all foreign key objects