Commit 2b01d706 authored by doctrine's avatar doctrine

Many-to-Many relation fetching, fatal proxy state bug fixed, fatal loaded...

Many-to-Many relation fetching, fatal proxy state bug fixed, fatal loaded identity map + multiple component fetching bug fixed
parent abdcd65a
...@@ -180,6 +180,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -180,6 +180,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$record->rawSet($this->reference_field, $this->reference); $record->rawSet($this->reference_field, $this->reference);
} }
} }
} elseif($relation instanceof Doctrine_Association) {
} }
} }
/** /**
...@@ -249,7 +251,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -249,7 +251,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} elseif($this->relation instanceof Doctrine_Association) { } elseif($this->relation instanceof Doctrine_Association) {
$asf = $fk->getAssociationFactory(); $asf = $this->relation->getAssociationFactory();
$query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getID(); $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getID();
$table = $fk->getTable(); $table = $fk->getTable();
...@@ -411,6 +413,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -411,6 +413,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key] = $record; $this->data[$key] = $record;
return true; return true;
} }
if(in_array($record,$this->data)) {
return false;
} else
if(isset($this->generator)) { if(isset($this->generator)) {
$key = $this->generator->getIndex($record); $key = $this->generator->getIndex($record);
......
...@@ -467,28 +467,36 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -467,28 +467,36 @@ class Doctrine_Query extends Doctrine_Access {
$coll->add($record); $coll->add($record);
} else { } else {
$pointer = $this->joins[$name]; $pointer = $this->joins[$name];
$alias = $this->tables[$pointer]->getAlias($name);
//print "fetching data : ".$pointer." ".$alias."<br \>";
$fk = $this->tables[$pointer]->getForeignKey($alias);
$fk = $this->tables[$pointer]->getForeignKey($this->tables[$pointer]->getAlias($name)); $last = $prev[$pointer]->getLast();
switch($fk->getType()): switch($fk->getType()):
case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::ONE_AGGREGATE: case Doctrine_Relation::ONE_AGGREGATE:
$last = $prev[$pointer]->getLast();
$last->rawSet($this->connectors[$name]->getLocal(), $record->getID()); $last->rawSet($this->connectors[$name]->getLocal(), $record->getID());
$last->initSingleReference($record); $last->initSingleReference($record);
$prev[$name] = $record; $prev[$name] = $record;
break; break;
default: default:
// one-to-many relation or many-to-many relation // one-to-many relation or many-to-many relation
$last = $prev[$pointer]->getLast();
if( ! $last->hasReference($alias)) {
if( ! $last->hasReference($name)) { //print "initializing reference : ".$name." ".$alias;
$prev[$name] = $this->getCollection($name); $prev[$name] = $this->getCollection($name);
$last->initReference($prev[$name],$this->connectors[$name]); $last->initReference($prev[$name],$this->connectors[$name]);
} else {
// previous entry found from identityMap
$prev[$name] = $last->get($alias);
} }
//print "adding reference : ".$pointer." -> ".$name." as ".$alias."<br \>";
$last->addReference($record); $last->addReference($record);
endswitch; endswitch;
} }
...@@ -930,37 +938,35 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -930,37 +938,35 @@ class Doctrine_Query extends Doctrine_Access {
$this->connectors[$name] = $fk; $this->connectors[$name] = $fk;
switch($mark):
case ":":
$join = 'INNER JOIN ';
break;
case ".":
$join = 'LEFT JOIN ';
break;
default:
throw new Doctrine_Exception("Unknown operator '$mark'");
endswitch;
if($fk instanceof Doctrine_ForeignKey || if($fk instanceof Doctrine_ForeignKey ||
$fk instanceof Doctrine_LocalKey) { $fk instanceof Doctrine_LocalKey) {
switch($mark): $this->parts["join"][$tname][$tname2] = $join.$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
case ":":
$this->parts["join"][$tname][$tname2] = "INNER JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
break;
case ".":
$this->parts["join"][$tname][$tname2] = "LEFT JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
break;
endswitch;
$c = $table->getComponentName();
$this->joins[$name] = $c;
} elseif($fk instanceof Doctrine_Association) { } elseif($fk instanceof Doctrine_Association) {
$asf = $fk->getAssociationFactory(); $asf = $fk->getAssociationFactory();
switch($fk->getType()): $assocTableName = $asf->getTableName();
case Doctrine_Relation::ONE_AGGREGATE:
case Doctrine_Relation::ONE_COMPOSITE:
break;
case Doctrine_Relation::MANY_AGGREGATE:
case Doctrine_Relation::MANY_COMPOSITE:
//$this->addWhere("SELECT ".$fk->getLocal()." FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." IN (SELECT ".$fk->getTable()->getComponentName().")"); $this->parts["join"][$tname][$assocTableName] = $join.$assocTableName." ON ".$tname.".id = ".$assocTableName.".".$fk->getLocal();
$this->parts["from"][$tname] = true; $this->parts["join"][$tname][$tname2] = $join.$tname2." ON ".$tname2.".id = ".$assocTableName.".".$fk->getForeign();
break;
endswitch;
} }
$c = $table->getComponentName();
$this->joins[$name] = $c;
$table = $fk->getTable(); $table = $fk->getTable();
} }
...@@ -992,7 +998,7 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -992,7 +998,7 @@ class Doctrine_Query extends Doctrine_Access {
} }
} catch(Exception $e) { } catch(Exception $e) {
throw new DQLException($e->getMessage(),$e->getCode()); throw new DQLException($e->__toString());
} }
} }
} }
......
...@@ -98,7 +98,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -98,7 +98,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/ */
private static $index = 1; private static $index = 1;
/** /**
* @var Doctrine_Null $null a Doctrine_Null object used for extremely fast * @var Doctrine_Null $null a Doctrine_Null object used for extremely fast
* null value testing * null value testing
*/ */
private static $null; private static $null;
...@@ -153,7 +153,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -153,7 +153,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->prepareIdentifiers($exists); $this->prepareIdentifiers($exists);
if( ! $exists) { if( ! $exists) {
if($count > 0) if($count > 0)
$this->state = Doctrine_Record::STATE_TDIRTY; $this->state = Doctrine_Record::STATE_TDIRTY;
else else
...@@ -169,7 +169,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -169,7 +169,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->state = Doctrine_Record::STATE_PROXY; $this->state = Doctrine_Record::STATE_PROXY;
} }
// listen the onLoad event // listen the onLoad event
$this->table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this); $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this);
} }
...@@ -219,6 +218,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -219,6 +218,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$tmp = $this->data; $tmp = $this->data;
$this->data = array(); $this->data = array();
$count = 0;
foreach($this->table->getColumnNames() as $name) { foreach($this->table->getColumnNames() as $name) {
$type = $this->table->getTypeOf($name); $type = $this->table->getTypeOf($name);
...@@ -239,9 +240,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -239,9 +240,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
break; break;
default: default:
$this->data[$name] = $tmp[$name]; $this->data[$name] = $tmp[$name];
$count++;
endswitch; endswitch;
} }
} }
return $count;
} }
/** /**
* prepares identifiers for later use * prepares identifiers for later use
...@@ -973,7 +976,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -973,7 +976,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/ */
public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) { public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) {
$name = $this->table->getAlias($coll->getTable()->getComponentName()); $name = $this->table->getAlias($coll->getTable()->getComponentName());
$coll->setReference($this, $connector);
if( ! ($connector instanceof Doctrine_Association))
$coll->setReference($this, $connector);
$this->references[$name] = $coll; $this->references[$name] = $coll;
$this->originals[$name] = clone $coll; $this->originals[$name] = clone $coll;
} }
......
...@@ -159,6 +159,7 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -159,6 +159,7 @@ class Doctrine_Table extends Doctrine_Configurable {
$this->primaryKeys[] = "id"; $this->primaryKeys[] = "id";
$this->identifier = "id"; $this->identifier = "id";
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT; $this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
$this->columnCount++;
break; break;
default: default:
if(count($this->primaryKeys) > 1) { if(count($this->primaryKeys) > 1) {
...@@ -804,7 +805,7 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -804,7 +805,7 @@ class Doctrine_Table extends Doctrine_Configurable {
* @return integer * @return integer
*/ */
final public function getColumnCount() { final public function getColumnCount() {
return $this->columnCount; return $this->columnCount;
} }
/** /**
* returns all columns and their definitions * returns all columns and their definitions
......
...@@ -120,11 +120,12 @@ class Doctrine_Validator { ...@@ -120,11 +120,12 @@ class Doctrine_Validator {
$column = $columns[$key]; $column = $columns[$key];
if($column[0] == 'array' || $column[0] == 'object') { if($column[0] == 'array' || $column[0] == 'object')
$value = serialize($value); $length = strlen(serialize($value));
} else
$length = strlen($value);
if(strlen($value) > $column[1]) { if($length > $column[1]) {
$err[$key] = Doctrine_Validator::ERR_LENGTH; $err[$key] = Doctrine_Validator::ERR_LENGTH;
continue; continue;
} }
......
...@@ -2,12 +2,32 @@ ...@@ -2,12 +2,32 @@
Doctrine::autoload('Doctrine_Exception'); Doctrine::autoload('Doctrine_Exception');
class Doctrine_Validator_Exception extends Doctrine_Exception { class Doctrine_Validator_Exception extends Doctrine_Exception {
/**
* @var Doctrine_Validator $validator
*/
private $validator; private $validator;
/**
* @param Doctrine_Validator $validator
*/
public function __construct(Doctrine_Validator $validator) { public function __construct(Doctrine_Validator $validator) {
$this->validator = $validator; $this->validator = $validator;
} }
/**
* returns the error stack
*
* @return array
*/
public function getErrorStack() { public function getErrorStack() {
return $this->validator->getErrorStack(); return $this->validator->getErrorStack();
} }
/**
* __toString
*
* @return string
*/
public function __toString() {
$string = "Error stack : ".print_r($this->validator->getErrorStack(), true);
return $string.parent::__toString();
}
} }
?> ?>
This diff is collapsed.
...@@ -46,7 +46,7 @@ $test->addTestCase(new Doctrine_CollectionTestCase()); ...@@ -46,7 +46,7 @@ $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_PessimisticLockingTestCase()); //$test->addTestCase(new Doctrine_PessimisticLockingTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
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