Doctrine, different file names, different tables generation
I am trying to create tables from models using the createTablesFromModels method of Doctrine. I have a /model
folder where I keep my models but it depends on the file names how the tables are generated.
Inside 3 files I have the following:
class Item extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('nombre', 'string', 45, array(
'notnull' => true
));
$this->hasColumn('enunciado', 'string', 90, array(
'notnull' => true
));
$this->hasColumn('imagen_reposo', 'string', 90);
$this->hasColumn('imagen_movimiento', 'string', 90);
}
public function setUp() {
$this->hasMany('Prueba as Pruebas', array(
'refClass' => 'ItemPrueba',
'local' => 'item_id',
'foreign' => 'prueba_id'
));
}
}
class Prueba extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('nombre', 'string', 45, array(
'notnull' => true
));
$this->hasColumn('consigna', 'clob', 65535);
$this->hasColumn('consentimiento', 'clob', 65535);
$this->hasColumn('codigo', 'string', 45);
}
public function setUp() {
开发者_如何学Go $this->hasMany('Item as Items', array(
'refClass' => 'ItemPrueba',
'local' => 'prueba_id',
'foreign' => 'item_id'
));
}
}
class ItemPrueba extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('item_id', 'integer', null, array(
'primary' => true
));
$this->hasColumn('prueba_id', 'integer', null, array(
'primary' => true
));
}
}
I just want to do a many to many relation. When I use this names:
/models/tableone.php
/models/tabletwo.php
/models/tableoneTabletwo.php
it creates the following tables with the relations.
http://i52.tinypic.com/25hpdo2.png
When I use this names:
/models/item.php
/models/prueba.php
/models/itemPrueba.php
it creates the tables without any relations
more info: I am using codeIgniter framework and added Doctrine 1.2 as a plugin
Adding
$this->setTableName('tablename');
should do what you need. Doctrine uses some conventions to identify relations and tables. It usually guesses the name of the table based on the class but I've seen this failing many times. Setting the table name should do what you want.
精彩评论