diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 6e2d50867..59cbf8e3b 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -253,13 +253,18 @@ class CakeSchema extends Object { } if (is_object($Object) && $Object->useTable !== false) { - $table = $db->fullTableName($Object, false); - if (in_array($table, $currentTables)) { - $key = array_search($table, $currentTables); + $fulltable = $table = $db->fullTableName($Object, false); + if ($prefix && strpos($table, $prefix) !== 0) { + continue; + } + $table = str_replace($prefix, '', $table); + + if (in_array($fulltable, $currentTables)) { + $key = array_search($fulltable, $currentTables); if (empty($tables[$table])) { $tables[$table] = $this->__columns($Object); $tables[$table]['indexes'] = $db->index($Object); - $tables[$table]['tableParameters'] = $db->readTableParameters($table); + $tables[$table]['tableParameters'] = $db->readTableParameters($fulltable); unset($currentTables[$key]); } if (!empty($Object->hasAndBelongsToMany)) { diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 3dc5fc9f5..c18184549 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -559,13 +559,6 @@ class CakeSchemaTest extends CakeTestCase { $this->Schema->tables['datatypes']['float_field'] ); - $db =& ConnectionManager::getDataSource('test_suite'); - $config = $db->config; - $config['prefix'] = 'schema_test_prefix_'; - ConnectionManager::create('schema_prefix', $config); - $read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false)); - $this->assertTrue(empty($read['tables'])); - $SchemaPost =& ClassRegistry::init('SchemaPost'); $SchemaPost->table = 'sts'; $SchemaPost->tablePrefix = 'po'; @@ -603,6 +596,20 @@ class CakeSchemaTest extends CakeTestCase { } +/** + * test reading schema with config prefix. + * + * @return void + */ + function testSchemaReadWithConfigPrefix() { + $db =& ConnectionManager::getDataSource('test_suite'); + $config = $db->config; + $config['prefix'] = 'schema_test_prefix_'; + ConnectionManager::create('schema_prefix', $config); + $read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false)); + $this->assertTrue(empty($read['tables'])); + } + /** * test reading schema from plugins. *