diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index a1ea24acef0..6e2d50867db 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -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); diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 3a769356ab3..3dc5fc9f52d 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -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);