views:

52

answers:

2

Hi,

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.

+2  A: 

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.

Darragh
I'm just wondering though.. is this really practical, because presumably you'll be rebuilding models which will entail dropping/creating/rebuilding your database, probably a lot. Which means you'll be dropping both sets of tables each time. Seems a lot more laborious than creating two databases, and defining a connection for each in the Doctrine_Manager.
Darragh
It's use case is for shared hosts which only allow one database. Another use case is for demo installs for CMS which due to server permission restrictions won't allow for automatic database creation.
balupton
hi. sorry about the delay. fair enough. so I guess what you could do is define two connections (with the same db credentials etc.) and then use the Doctrine_Manager to grab each instance by name... then set the desired tablename format for each, as above? Don't have time to check if that'll fly right now but it should work.
Darragh
A: 

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)

Jordi Cabot