Doctrine ORM - Prefixing Tables

2019-05-23 07:48发布

问题:

I'm using Doctrine 1.2, and would like to know how I can achieve mysql table prefixes with it.

So for instance I would like for our system to be deployed twice on the same database, the first the tables can be prefixed with "one_" and the second can be prefixed with "two_".

Anyone got any idea how to accomplish this? I would imagine it is a config setting but I just can't seem to find it.

回答1:

I haven't tried it but.. from the docs:

$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT, 'one_%s');

Alternatively, you can manually define a table name in your YAML schema:

Foo:
  tableName: one_foo
  columns:
    # etc.

Hope this helps.



回答2:

If you have a UML model of the domain, you can use this UML to Doctrine online service to generate different versions of the corresponding Doctrine script, each one with different prefixes for the tables (choosing a prefix is one of the configuration options you can change as part of the generation process)