Fixing connection specific schema generation

Fixing missing table errors when reading schema for specific connections.
Tests updated to check that tables not on a connection are never touched.  Fixes #1106
This commit is contained in:
mark_story 2010-09-30 23:22:57 -04:00
parent d83907a77d
commit 5e26d282a1
2 changed files with 16 additions and 8 deletions

View file

@ -234,17 +234,25 @@ class CakeSchema extends Object {
if (is_array($models)) {
foreach ($models as $model) {
$importModel = $model;
if (isset($this->plugin)) {
$model = $this->plugin . '.' . $model;
$importModel = $this->plugin . '.' . $model;
}
if (!App::import('Model', $importModel)) {
continue;
}
$vars = get_class_vars($model);
if (empty($vars['useDbConfig']) || $vars['useDbConfig'] != $connection) {
continue;
}
if (PHP5) {
$Object = ClassRegistry::init(array('class' => $model, 'ds' => null));
$Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection));
} else {
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => null));
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => $connection));
}
if (is_object($Object) && $Object->useTable !== false) {
$Object->setDataSource($connection);
$table = $db->fullTableName($Object, false);
if (in_array($table, $currentTables)) {
$key = array_search($table, $currentTables);

View file

@ -658,17 +658,17 @@ class CakeSchemaTest extends CakeTestCase {
'name' => 'TestApp',
'models' => array('SchemaCrossDatabase', 'SchemaPost')
));
unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['posts']));
$this->assertFalse(isset($read['tables']['cross_database']));
$this->assertFalse(isset($read['tables']['cross_database']), 'Cross database should not appear');
$this->assertFalse(isset($read['tables']['missing']['cross_database']), 'Cross database should not appear');
$read = $this->Schema->read(array(
'connection' => 'test2',
'name' => 'TestApp',
'models' => array('SchemaCrossDatabase', 'SchemaPost')
));
unset($read['tables']['missing']);
$this->assertFalse(isset($read['tables']['posts']));
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
$this->assertTrue(isset($read['tables']['cross_database']));
$fixture->drop($db2);