TreeStructure bug fixed
This commit is contained in:
parent
b636861742
commit
83d89b766d
@ -1315,10 +1315,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
*/
|
*/
|
||||||
final public function loadReference($name)
|
final public function loadReference($name)
|
||||||
{
|
{
|
||||||
|
|
||||||
$fk = $this->_table->getRelation($name);
|
$fk = $this->_table->getRelation($name);
|
||||||
|
|
||||||
if ($fk->isOneToOne()) {
|
if ($fk->isOneToOne()) {
|
||||||
$this->references[$name] = $fk->fetchRelatedFor($this);
|
$this->references[$name] = $fk->fetchRelatedFor($this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$coll = $fk->fetchRelatedFor($this);
|
$coll = $fk->fetchRelatedFor($this);
|
||||||
|
|
||||||
|
@ -171,9 +171,9 @@ abstract class Doctrine_Relation
|
|||||||
*/
|
*/
|
||||||
public function getRelationDql($count)
|
public function getRelationDql($count)
|
||||||
{
|
{
|
||||||
$dql = "FROM ".$this->table->getComponentName().
|
$dql = 'FROM ' . $this->table->getComponentName()
|
||||||
" WHERE ".$this->table->getComponentName(). '.' . $this->foreign.
|
. ' WHERE ' . $this->table->getComponentName() . '.' . $this->foreign
|
||||||
" IN (".substr(str_repeat("?, ", $count),0,-2).")";
|
. ' IN (' . substr(str_repeat('?, ', $count), 0, -2) . ')';
|
||||||
|
|
||||||
return $dql;
|
return $dql;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,10 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
|
|||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
$related = $this->table->create();
|
$related = $this->table->create();
|
||||||
} else {
|
} else {
|
||||||
$dql = "FROM ".$this->table->getComponentName()." WHERE ".$this->table->getComponentName().".".$this->foreign." = ?";
|
$dql = 'FROM ' . $this->table->getComponentName()
|
||||||
|
. ' WHERE ' . $this->table->getComponentName()
|
||||||
|
. '.' . $this->foreign . ' = ?';
|
||||||
|
|
||||||
$coll = $this->table->getConnection()->query($dql, array($id));
|
$coll = $this->table->getConnection()->query($dql, array($id));
|
||||||
$related = $coll[0];
|
$related = $coll[0];
|
||||||
}
|
}
|
||||||
@ -89,6 +92,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
|
|||||||
$related->set($this->foreign, $record, false);
|
$related->set($this->foreign, $record, false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
$related = new Doctrine_Collection($this->table);
|
$related = new Doctrine_Collection($this->table);
|
||||||
} else {
|
} else {
|
||||||
|
@ -699,17 +699,28 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
// ONE-TO-ONE
|
// ONE-TO-ONE
|
||||||
if ($type == Doctrine_Relation::ONE_COMPOSITE ||
|
if ($type == Doctrine_Relation::ONE_COMPOSITE ||
|
||||||
$type == Doctrine_Relation::ONE_AGGREGATE) {
|
$type == Doctrine_Relation::ONE_AGGREGATE) {
|
||||||
|
// tree structure parent relation found
|
||||||
|
|
||||||
if ( ! isset($local)) {
|
if ( ! isset($local)) {
|
||||||
$local = $table->getIdentifier();
|
$local = $table->getIdentifier();
|
||||||
}
|
}
|
||||||
$relation = new Doctrine_Relation_LocalKey($table, $foreign, $local, $type, $alias);
|
$relation = new Doctrine_Relation_LocalKey($table, $foreign, $local, $type, $alias);
|
||||||
} else {
|
} else {
|
||||||
|
// tree structure children relation found
|
||||||
|
|
||||||
|
if ( ! isset($local)) {
|
||||||
|
$tmp = $table->getIdentifier();
|
||||||
|
}
|
||||||
|
$local = $foreign;
|
||||||
|
$foreign = $tmp;
|
||||||
|
|
||||||
$relation = new Doctrine_Relation_ForeignKey($table, $foreign, $local, $type, $alias);
|
$relation = new Doctrine_Relation_ForeignKey($table, $foreign, $local, $type, $alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($component == $name ||
|
} elseif ($component == $name ||
|
||||||
($component == $alias)) { // && ($name == $this->options['name'] || in_array($name,$this->parents))
|
($component == $alias)) { // && ($name == $this->options['name'] || in_array($name,$this->parents))
|
||||||
|
|
||||||
|
|
||||||
if ( ! isset($local)) {
|
if ( ! isset($local)) {
|
||||||
$local = $this->identifier;
|
$local = $this->identifier;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,12 @@ class TreeLeaf extends Doctrine_Record
|
|||||||
{
|
{
|
||||||
public function setTableDefinition()
|
public function setTableDefinition()
|
||||||
{
|
{
|
||||||
|
$this->hasColumn('name', 'string');
|
||||||
$this->hasColumn('parent_id', 'integer');
|
$this->hasColumn('parent_id', 'integer');
|
||||||
$this->hasOne('TreeLeaf as Parent', 'TreeLeaf.parent_id', 'id');
|
}
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->hasOne('TreeLeaf as Parent', 'TreeLeaf.parent_id');
|
||||||
$this->hasMany('TreeLeaf as Children', 'TreeLeaf.parent_id');
|
$this->hasMany('TreeLeaf as Children', 'TreeLeaf.parent_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,6 +31,18 @@ class Doctrine_TreeStructure_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLocalAndForeignKeysAreSetCorrectly() {
|
||||||
|
$component = new TreeLeaf();
|
||||||
|
|
||||||
|
$rel = $component->getTable()->getRelation('Parent');
|
||||||
|
$this->assertEqual($rel->getLocal(), 'parent_id');
|
||||||
|
$this->assertEqual($rel->getForeign(), 'id');
|
||||||
|
|
||||||
|
$rel = $component->getTable()->getRelation('Children');
|
||||||
|
$this->assertEqual($rel->getLocal(), 'id');
|
||||||
|
$this->assertEqual($rel->getForeign(), 'parent_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function testTreeLeafRelationships()
|
public function testTreeLeafRelationships()
|
||||||
{
|
{
|
||||||
/* structure:
|
/* structure:
|
||||||
@ -42,22 +58,26 @@ class Doctrine_TreeStructure_TestCase extends Doctrine_UnitTestCase
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$o1 = new TreeLeaf();
|
$o1 = new TreeLeaf();
|
||||||
$o1->Parent = null;
|
$o1->name = 'o1';
|
||||||
$o1->save();
|
$o1->save();
|
||||||
|
|
||||||
$o2 = new TreeLeaf();
|
$o2 = new TreeLeaf();
|
||||||
|
$o2->name = 'o2';
|
||||||
$o2->Parent = $o1;
|
$o2->Parent = $o1;
|
||||||
$o2->save();
|
$o2->save();
|
||||||
|
|
||||||
$o3 = new TreeLeaf();
|
$o3 = new TreeLeaf();
|
||||||
|
$o3->name = 'o3';
|
||||||
$o3->Parent = $o1;
|
$o3->Parent = $o1;
|
||||||
$o3->save();
|
$o3->save();
|
||||||
|
|
||||||
$o1->refresh();
|
//$o1->refresh();
|
||||||
|
|
||||||
$o4 = new TreeLeaf();
|
$o4 = new TreeLeaf();
|
||||||
|
$o4->name = 'o4';
|
||||||
$o4->save();
|
$o4->save();
|
||||||
|
|
||||||
|
$o1->Children;
|
||||||
$this->assertFalse(isset($o1->Parent));
|
$this->assertFalse(isset($o1->Parent));
|
||||||
$this->assertTrue(count($o1->Children) == 2);
|
$this->assertTrue(count($o1->Children) == 2);
|
||||||
$this->assertTrue(count($o1->get('Children')) == 2);
|
$this->assertTrue(count($o1->get('Children')) == 2);
|
||||||
|
@ -136,7 +136,6 @@ $test->addTestCase(new Doctrine_Collection_TestCase());
|
|||||||
$test->addTestCase(new Doctrine_Relation_TestCase());
|
$test->addTestCase(new Doctrine_Relation_TestCase());
|
||||||
$test->addTestCase(new Doctrine_Relation_Access_TestCase());
|
$test->addTestCase(new Doctrine_Relation_Access_TestCase());
|
||||||
$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
|
$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
|
||||||
$test->addTestCase(new Doctrine_TreeStructure_TestCase());
|
|
||||||
|
|
||||||
|
|
||||||
// Datatypes
|
// Datatypes
|
||||||
@ -192,9 +191,10 @@ $test->addTestCase(new Doctrine_Query_AggregateValue_TestCase());
|
|||||||
$test->addTestCase(new Doctrine_Query_Select_TestCase());
|
$test->addTestCase(new Doctrine_Query_Select_TestCase());
|
||||||
$test->addTestCase(new Doctrine_Query_Expression_TestCase());
|
$test->addTestCase(new Doctrine_Query_Expression_TestCase());
|
||||||
$test->addTestCase(new Doctrine_Query_Having_TestCase());
|
$test->addTestCase(new Doctrine_Query_Having_TestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
|
$test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
|
||||||
|
|
||||||
|
|
||||||
|
$test->addTestCase(new Doctrine_TreeStructure_TestCase());
|
||||||
// Cache tests
|
// Cache tests
|
||||||
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
|
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
|
||||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user