2010-12-11 45 views
0

我想從模型創建表使用createTablesFromModels方法的原則。我有一個/model文件夾,我保留我的模型,但它取決於文件名如何生成表。學說,不同的文件名,不同的表代

內3個文件我有以下幾點:

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() { 
    $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 
    )); 
} 
} 

我只想做一個多對多的關係。 當我使用這個名字:

/models/tableone.php 
/models/tabletwo.php 
/models/tableoneTabletwo.php 

它會創建下列表格關係。

http://i52.tinypic.com/25hpdo2.png

當我使用這個名字:

/models/item.php 
/models/prueba.php 
/models/itemPrueba.php 

它創建表沒有任何關係

更多信息: 我使用CodeIgniter的框架,並添加學說1.2作爲插件

回答

0

添加

$this->setTableName('tablename'); 

應該做你所需要的。學說使用一些約定來確定關係和表格。它通常根據班級猜測表的名字,但我多次看到這個失敗。設置表名應該做你想要的。

+0

感謝您的答案,但它沒有奏效。我不得不將文件名prueba.php更改爲prueb.php。奇怪的解決方案,我仍然不知道爲什麼我不能在我的模型類中使用文件名prueba.php。 – petingo0 2010-12-12 17:43:39

相關問題