2

如何基于抽象实体类在学说中动态创建实体?表名必须不同。例如

// abstract entity model
class Transport {
   // $name, $type and other columns
}

创作看起来像:

class TransportManager {

public function registerTransport($name) {
$car = ...
// here create table $name if does not exist, 
// and if it exists then just
// return Car instance of this $name table
return $car;

}

用法:

$car = $transportManager->registerTransport('car');
$airplain = $transportManager->registerTransport('airplain');
$train = $transportManager->registerTransport('train');
$helicopter = $transportManager->registerTransport('helicopter');

原因?我有几个(> 10)具有相同结构的表,我想将所有数据保存在单独的表中,以防止每个表的加载

4

3 回答 3

0

I'd try something like this, although not exactly the approach you were trying:

$metadata = $cmf->getMetadataFor('YourBundle:Transport');
$metadata->setTableName('car');
//work with car
$metadata->setTableName('airplain');
//work with airplain

Hope it serves.

于 2014-10-23T21:32:12.093 回答
0

使用一张桌子。通过适当的索引,它不应该比使用多个表慢,即使它很大。

于 2013-12-21T01:02:36.343 回答
0

Doctrine 支持继承:http ://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html

您也可以批量生成新实体,但这取决于您的工作流程(例如,为新实体创建代码、生成迁移、执行迁移等)

于 2013-07-31T15:55:40.307 回答