Commit d899509c authored by doctrine's avatar doctrine

minor bug fix

parent 7a020a52
......@@ -491,6 +491,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $name
*/
public function loadRelated($name) {
$rel = $this->table->getForeignKey($name);
$table = $rel->getTable();
$query = new Doctrine_Query($this->table->getSession());
......@@ -527,11 +528,14 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
" FROM ".$asf->getTableName().
" WHERE ".$local.
" IN ".$paramStr;
$table->getForeignKey($table->getAlias($this->table->getComponentName()));
$dql = "FROM ".$table->getComponentName().":".$asf->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($sub)";
//$query->parseQuery($dql);
//$query->parseQuery($dql);
//print Doctrine_Lib::formatSql($query->getQuery());
}
$coll = $query->query($dql, $list);
......
......@@ -27,7 +27,38 @@ require_once("Access.php");
* @license LGPL
*/
class Doctrine_Query extends Doctrine_Hydrate {
/**
* count
*
* @return integer
*/
public function count(Doctrine_Table $table, $params = array()) {
$this->remove('select');
$join = $this->join;
$where = $this->where;
$having = $this->having;
$q = "SELECT COUNT(1) FROM ".$table." ";
foreach($join as $j) {
$q .= implode(" ",$j);
}
$string = $query->applyInheritance();
if( ! empty($where)) {
$q .= " WHERE ".implode(" AND ",$where);
if( ! empty($string))
$q .= " AND (".$string.")";
} else {
if( ! empty($string))
$q .= " WHERE (".$string.")";
}
if( ! empty($having))
$q .= " HAVING ".implode(' AND ',$having);
$a = $this->table->getSession()->execute($q, $params)->fetch(PDO::FETCH_NUM);
return $a[0];
}
/**
* loadFields
* loads fields for a given table and
......@@ -230,7 +261,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
$string = $this->applyInheritance();
if( ! empty($this->parts["where"])) {
$q .= " WHERE ".implode(" ",$this->parts["where"]);
$q .= " WHERE ".implode(" AND ",$this->parts["where"]);
if( ! empty($string))
$q .= " AND (".$string.")";
} else {
......@@ -601,5 +632,4 @@ class Doctrine_Query extends Doctrine_Hydrate {
$this->loadFields($table, $fetchmode, $fields, $currPath);
}
}
?>
......@@ -260,16 +260,22 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$type = $this->table->getTypeOf($name);
if( ! isset($tmp[$name])) {
if($type == 'array') {
$this->data[$name] = array();
} else
//if($type == 'array') {
// $this->data[$name] = array();
//} else
$this->data[$name] = self::$null;
} else {
switch($type):
case "array":
case "object":
if($tmp[$name] !== self::$null)
$this->data[$name] = unserialize($tmp[$name]);
if($tmp[$name] !== self::$null) {
$value = unserialize($tmp[$name]);
if($value === false)
throw new Doctrine_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true));
print_r($value);
$this->data[$name] = $value;
}
break;
case "enum":
$this->data[$name] = $this->table->enumValue($name, $tmp[$name]);
......@@ -280,6 +286,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$count++;
}
}
return $count;
}
/**
......@@ -476,7 +483,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
final public function factoryRefresh() {
$data = $this->table->getData();
$this->data = $this->table->getData();
$old = $this->id;
$this->cleanData();
......@@ -486,8 +493,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if($this->id != $old)
throw new Doctrine_Record_Exception();
$this->data = $data;
$this->state = Doctrine_Record::STATE_CLEAN;
$this->modified = array();
......@@ -637,9 +642,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
public function set($name,$value) {
if(is_array($value))
throw new Exception($value);
if(isset($this->data[$name])) {
if($value instanceof Doctrine_Record) {
......
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