Commit 563377cc authored by Jonathan.Wage's avatar Jonathan.Wage

Fix for missing sql when creating tables for model with templates that result in addition tables

parent e33130b8
...@@ -1073,24 +1073,25 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -1073,24 +1073,25 @@ class Doctrine_Export extends Doctrine_Connection_Module
} }
$sql = $this->exportClassesSql(array($class)); $sql = $this->exportClassesSql(array($class));
// The create sql query is the first one, and everything else is the alters // Build array of all the creates
$create = $sql[0]; // We need these to happen first
foreach ($sql as $key => $query) {
// Remove create from the main array if (strstr($query, 'CREATE')) {
unset($sql[0]); $connections[$connectionName]['creates'][] = $query;
// Unset the create from sql so we can have an array of everything else but creates
unset($sql[$key]);
}
}
// Store the creates and alters individually so we can merge them back together later
// We need the creates to happen first, then the alters
$connections[$connectionName]['creates'][] = $create;
$connections[$connectionName]['alters'] = array_merge($connections[$connectionName]['alters'], $sql); $connections[$connectionName]['alters'] = array_merge($connections[$connectionName]['alters'], $sql);
} }
// Loop over all the sql again to merge the creates and alters in to the same array, but so that the alters are at the bottom // Loop over all the sql again to merge the creates and alters in to the same array, but so that the alters are at the bottom
$build = array(); $build = array();
foreach ($connections as $connectionName => $sql) { foreach ($connections as $connectionName => $sql) {
$build[$connectionName] = array_merge($sql['creates'], $sql['alters']); $build[$connectionName] = array_merge($sql['creates'], $sql['alters']);
} }
foreach ($build as $connectionName => $sql) { foreach ($build as $connectionName => $sql) {
$connection = Doctrine_Manager::getInstance()->getConnection($connectionName); $connection = Doctrine_Manager::getInstance()->getConnection($connectionName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment