Fixes #180
This commit is contained in:
parent
20f504253b
commit
599dc759fb
@ -540,7 +540,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
$this->table->getConnection()->execute($query, array($r->getIncremented(),$record->getIncremented()));
|
||||
}
|
||||
|
||||
$operations = Doctrine_Relation::getInsertOperations($this->originals[$alias],$new);
|
||||
$operations = Doctrine_Relation::getInsertOperations($record->obtainOriginals($alias),$new);
|
||||
foreach($operations as $r) {
|
||||
$reldao = $asf->create();
|
||||
$reldao->set($fk->getForeign(),$r);
|
||||
@ -548,14 +548,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
$reldao->save();
|
||||
|
||||
}
|
||||
$this->originals[$alias] = clone $this->references[$alias];
|
||||
$record->assignOriginals($alias, clone $this->references[$alias]);
|
||||
}
|
||||
} elseif($fk instanceof Doctrine_Relation_ForeignKey ||
|
||||
$fk instanceof Doctrine_Relation_LocalKey) {
|
||||
|
||||
if($fk->isOneToOne()) {
|
||||
if(isset($this->originals[$alias]) && $this->originals[$alias]->obtainIdentifier() != $this->references[$alias]->obtainIdentifier())
|
||||
$this->originals[$alias]->delete();
|
||||
if($record->obtainOriginals($alias) && $record->obtainOriginals($alias)->obtainIdentifier() != $this->references[$alias]->obtainIdentifier())
|
||||
$record->obtainOriginals($alias)->delete();
|
||||
} else {
|
||||
if(isset($this->references[$alias])) {
|
||||
$new = $this->references[$alias];
|
||||
|
@ -434,7 +434,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$vars = get_object_vars($this);
|
||||
|
||||
unset($vars['references']);
|
||||
unset($vars['collections']);
|
||||
unset($vars['originals']);
|
||||
unset($vars['_table']);
|
||||
|
||||
@ -638,7 +637,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
|
||||
if($this->_data[$lower] === self::$null)
|
||||
$this->load();
|
||||
|
||||
|
||||
|
||||
if($this->_data[$lower] === self::$null)
|
||||
$value = null;
|
||||
@ -854,12 +853,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
return $a;
|
||||
}
|
||||
/**
|
||||
* getPrepared
|
||||
*
|
||||
* returns an array of modified fields and values with data preparation
|
||||
* adds column aggregation inheritance and converts Records into primary key values
|
||||
*
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
final public function getPrepared(array $array = array()) {
|
||||
public function getPrepared(array $array = array()) {
|
||||
$a = array();
|
||||
|
||||
if(empty($array))
|
||||
@ -968,6 +970,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function getIterator() {
|
||||
return new Doctrine_Record_Iterator($this);
|
||||
}
|
||||
|
||||
public function obtainOriginals($name) {
|
||||
if(isset($this->originals[$name]))
|
||||
return $this->originals[$name];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* saveAssociations
|
||||
*
|
||||
|
@ -89,7 +89,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
/**
|
||||
* @var array $columns an array of column definitions
|
||||
*/
|
||||
private $columns;
|
||||
private $columns = array();
|
||||
/**
|
||||
* @var array $bound bound relations
|
||||
*/
|
||||
@ -103,8 +103,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
* determining its state
|
||||
*/
|
||||
private $columnCount;
|
||||
|
||||
|
||||
/**
|
||||
* @var array $inheritanceMap inheritanceMap is used for inheritance mapping, keys representing columns and values
|
||||
* the column values that should correspond to child classes
|
||||
@ -229,7 +227,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new Doctrine_Exception("Class '$name' has no table definition.");
|
||||
throw new Doctrine_Table_Exception("Class '$name' has no table definition.");
|
||||
}
|
||||
|
||||
|
||||
@ -589,7 +587,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
$original = $name;
|
||||
|
||||
if(isset($this->relations[$name]))
|
||||
return $this->relations[$name];
|
||||
return $this->relations[$name];
|
||||
|
||||
if(isset($this->bound[$name])) {
|
||||
$type = $this->bound[$name][1];
|
||||
@ -612,8 +610,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
} else
|
||||
throw new Doctrine_Table_Exception("Only one-to-one relations are possible when local reference key is used.");
|
||||
|
||||
} elseif($component == $name ||
|
||||
($component == $alias && ($name == $this->name || in_array($name,$this->parents)))) {
|
||||
} elseif($component == $name ||
|
||||
($component == $alias)) { // && ($name == $this->name || in_array($name,$this->parents))
|
||||
|
||||
if( ! isset($local))
|
||||
$local = $this->identifier;
|
||||
@ -666,9 +664,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->relations[$alias] = $relation;
|
||||
return $this->relations[$alias];
|
||||
}
|
||||
|
||||
// load all relations
|
||||
$this->getRelations();
|
||||
|
||||
|
@ -1,8 +1,72 @@
|
||||
<?php
|
||||
class RelationTest extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
|
||||
}
|
||||
public function setUp() {
|
||||
$this->ownsMany('OwnsOneToManyWithAlias as AliasO2M', 'AliasO2M.component_id');
|
||||
$this->hasMany('HasManyToManyWithAlias as AliasM2M', 'JoinTable.c1_id');
|
||||
}
|
||||
}
|
||||
class HasOneToOne extends Doctrine_Record {
|
||||
|
||||
}
|
||||
class HasOneToOneWithAlias extends Doctrine_Record {
|
||||
|
||||
}
|
||||
class JoinTable extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn('c1_id', 'integer');
|
||||
$this->hasColumn('c2_id', 'integer');
|
||||
}
|
||||
}
|
||||
class HasManyWithAlias extends Doctrine_Record {
|
||||
|
||||
}
|
||||
class OwnsOneToManyWithAlias extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn('component_id', 'integer');
|
||||
}
|
||||
public function setUp() {
|
||||
|
||||
}
|
||||
}
|
||||
class HasManyToManyWithAlias extends Doctrine_Record {
|
||||
public function setTableDefinition() { }
|
||||
public function setUp() {
|
||||
$this->hasMany('RelationTest as AliasM2M', 'JoinTable.c2_id');
|
||||
}
|
||||
}
|
||||
class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() {
|
||||
$this->tables = array();
|
||||
$this->tables = array();
|
||||
}
|
||||
|
||||
public function testOneToManyOwnsRelationWithAliases() {
|
||||
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, false);
|
||||
|
||||
$component = new RelationTest();
|
||||
|
||||
try {
|
||||
$rel = $component->getTable()->getRelation('AliasO2M');
|
||||
$this->pass();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
$this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey);
|
||||
}
|
||||
public function testManyToManyHasRelationWithAliases() {
|
||||
$component = new RelationTest();
|
||||
|
||||
try {
|
||||
$rel = $component->getTable()->getRelation('AliasM2M');
|
||||
$this->pass();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
|
||||
}
|
||||
public function testManyToManyRelation() {
|
||||
$user = new User();
|
||||
@ -31,5 +95,7 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
|
||||
$user = new User();
|
||||
|
||||
$this->assertTrue($user->getTable()->getRelation('Phonenumber') instanceof Doctrine_Relation_ForeignKey);
|
||||
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,14 +56,14 @@ print "<pre>";
|
||||
|
||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
$test->addTestCase(new Doctrine_Relation_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_ValidatorTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Relation_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_EventListenerTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Connection_Transaction_TestCase());
|
||||
|
Loading…
x
Reference in New Issue
Block a user