#1035: Creating Tree does not set reference keys
-----------------------+----------------------------------------------------
Reporter: sigma | Owner: romanb
Type: defect | Status: new
Priority: minor | Milestone: 0.11.2
Component: NestedSet | Version: 0.11
Keywords: |
-----------------------+----------------------------------------------------
Using Doctrine 0.10.4
First of all, I'm pretty inexperienced with nested set like doctrine uses
them. So I'm not quite sure if this is really a bug...
Here are my model classes:
{{{
class Item extends Doctrine_Record {
public function setTableDefinition() {
$this->setTableName('item');
$this->hasColumn('id', 'integer', 10, array('notnull' => true,
'primary' => true,
'unsigned' > true,
'autoincrement' =>
true));
$this->hasColumn('name', 'string' , 40 , array ('notnull' =>
true));
}
public function setUp() {
$this->hasOne('ItemTree', array('foreign' => 'item_id',
'local' => 'id'));
}
}
class ItemTree extends Doctrine_Record {
public function setTableDefinition() {
$this->setTableName('item_tree');
$this->hasColumn('id', 'integer', 10, array('notnull' => true,
'primary' => true,
'unsigned' > true,
'autoincrement' =>
true));
$this->hasColumn('item_id' , 'integer' , 10 , array ('notnull' =>
true));
$options = array('hasManyRoots' => true, 'rootColumnName' =>
'root_id');
$this->actAs('NestedSet', $options);
}
public function setUp() {
$this->hasMany('Item', array('local' => 'item_id',
'foreign' => 'id'));
}
}
}}}
My script for building the tree:
{{{
// creating root
$item = new Item();
$item->name = 'Root';
$rootNode = new ItemTree();
$rootNode->Item[] = $item;
$tree = $conn->getTable('ItemTree')->getTree();
$tree->createRoot( $rootNode );
for ( $i=0; $i<5; $i++ ) {
$item = new Item();
$item->name = 'Entry at '.$i.' - 1';
$node = new ItemTree();
$node->Item[] = $item;
$node->getNode()->insertAsFirstChildOf( $rootNode );
for ( $j=0; $j<3; $j++ ) {
$innerItem = new Item();
$innerItem->name = 'Entry at '.$i.' - 2 - '.$j;
$nextNode = new ItemTree();
$nextNode->Item[] = $innerItem;
$nextNode->getNode()->insertAsFirstChildOf( $node );
}
}
}}}
After a built the tree I took a look into the database table item_tree and
saw that everything looks good beside my foreign key to the column
'item_id'. Doctrine didn't set this relation although it is defined in the
model class. Why? Is it a bug or it this the way it should be?
Obviously there is a one-to-one relation between
item.id and
item_tree.id,
right?!
--
Ticket URL: <
http://trac.phpdoctrine.org/ticket/1035>
Doctrine <
http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper