tags:

views:

1302

answers:

5

When I use Doctrine to generate classes from Yaml/db each Base class (which includes the table definition) extends the Doctrine_Record class.

Since my app uses a master and (multiple) slave db servers I need to be able to make the Base classes extend my custom record class to force writes to go to the master db server (as described here). However if I change the base class manually I lose it again when I regenerate my classes from Yaml/db using Doctrine.

I need to find a way of telling Doctrine to extend my own Base class, or find a different solution to a master/slave db setup using Doctrine.

Example generated model:

abstract class My_Base_User extends Doctrine_Record
{

However I need it to be automatically generated as:

abstract class My_Base_User extends My_Record
{

I am using Doctrine 1.2.1 in a new Zend Framework 1.9.6 application if it makes any difference.

+4  A: 

Typical, as soon as I ask the question I manage to find the answer. I'm recording it here in case anyone else has the same issue.

You can pass in the parameter 'baseClassName' into the generateModels* methods and Doctrine will use that as the Base record class.

Examples:

Doctrine_Core::generateModelsFromDb('models', array('master'), array('generateTableClasses' => true, 'baseClassName' => 'My_Record'));

or using Cli:

$options['generate_models_options'] = array(
'pearStyle'             => true,
'baseClassPrefix'       => 'My_',
'baseClassName'         => 'My_Record',
'classPrefix'           => '',
'classPrefixFiles'      => false,
'generateTableClasses'  => true,
);

$cli = new Doctrine_Cli($options);
Shane O'Grady
A: 

Exactly what i was looking for, thanks!

Vitor Mello
A: 

Perfect, thanks! This is cool because I grab doctrine options from my application.ini in my Zend Framework project of a similar version (1.9.x). Now I can simply modify the ini to add the baseClassName like so:

doctrine.generate_models_options.baseClassName = "BaseRecord"

Thanks again for saving me time figuring this out on my own :)

thekingoftruth
A: 

Excellent ! Thumbs up for this solution !

Skipper
A: 

Excellent solution, thank you very much man, appreciated!