Skip to content

Commit

Permalink
Fixing connection specific schema generation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markstory committed Oct 1, 2010
1 parent d83907a commit 5e26d28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions cake/libs/model/cake_schema.php
Expand Up @@ -234,17 +234,25 @@ function read($options = array()) {

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);
Expand Down
8 changes: 4 additions & 4 deletions cake/tests/cases/libs/model/cake_schema.test.php
Expand Up @@ -658,17 +658,17 @@ function testSchemaReadWithCrossDatabase() {
'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);
Expand Down

0 comments on commit 5e26d28

Please sign in to comment.