I had this exact same scenario and ended up writing my own function to solve it. This function goes through my YAML file, reads each table name, and adds the appropriate className:
entry without the table prefix.
Here's the function:
const TABLE_PFX = 'tableName:';
const CLASS_PFX = 'className:';
function AddClassNames($yamlPath) {
$tempFilePath = $yamlPath . '.old';
rename($yamlPath, $tempFilePath);
$tempFile = fopen($tempFilePath, 'r');
$yamlFile = fopen($yamlPath, 'w');
while (!feof($tempFile)) {
$line = fgets($tempFile);
fwrite($yamlFile, $line);
if ($index = strpos($line, TABLE_PFX)) {
$tableName = trim(substr($line, $index + strlen(TABLE_PFX) + 1));
$className = substr($tableName, 4);
$className = strtocamel($className);
$classLine = str_replace(TABLE_PFX, CLASS_PFX, $line);
$classLine = str_replace($tableName, $className, $classLine);
fwrite($yamlFile, $classLine);
}
}
fclose($tempFile);
fclose($yamlFile);
unlink($tempFilePath);
}
And here's how I use it:
Doctrine_Core::generateYamlFromDb($yamlPath);
AddClassNames($yamlPath);
Doctrine_Core::generateModelsFromYaml($yamlPath, 'models',
array('doctrine'),
array('generateTableClasses' => true,));
One further note - with this method you don't have the luxury of Doctrine converting your database_table_name
to the PHP-friendly ClassName
, so you have to do this yourself. I used the strtocamel
function from here.