mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Fixing issue where table name was not using fully qualified table names, causing issues with models using table prefixes. Tests added. Fixes #623
This commit is contained in:
parent
1c064788c5
commit
af6435ece8
2 changed files with 57 additions and 12 deletions
|
@ -249,10 +249,10 @@ class CakeSchema extends Object {
|
||||||
|
|
||||||
if (in_array($table, $currentTables)) {
|
if (in_array($table, $currentTables)) {
|
||||||
$key = array_search($table, $currentTables);
|
$key = array_search($table, $currentTables);
|
||||||
if (empty($tables[$Object->table])) {
|
if (empty($tables[$table])) {
|
||||||
$tables[$Object->table] = $this->__columns($Object);
|
$tables[$table] = $this->__columns($Object);
|
||||||
$tables[$Object->table]['indexes'] = $db->index($Object);
|
$tables[$table]['indexes'] = $db->index($Object);
|
||||||
$tables[$Object->table]['tableParameters'] = $db->readTableParameters($table);
|
$tables[$table]['tableParameters'] = $db->readTableParameters($table);
|
||||||
unset($currentTables[$key]);
|
unset($currentTables[$key]);
|
||||||
}
|
}
|
||||||
if (!empty($Object->hasAndBelongsToMany)) {
|
if (!empty($Object->hasAndBelongsToMany)) {
|
||||||
|
@ -261,12 +261,12 @@ class CakeSchema extends Object {
|
||||||
$class = $assocData['with'];
|
$class = $assocData['with'];
|
||||||
}
|
}
|
||||||
if (is_object($Object->$class)) {
|
if (is_object($Object->$class)) {
|
||||||
$table = $db->fullTableName($Object->$class, false);
|
$withTable = $db->fullTableName($Object->$class, false);
|
||||||
if (in_array($table, $currentTables)) {
|
if (in_array($withTable, $currentTables)) {
|
||||||
$key = array_search($table, $currentTables);
|
$key = array_search($table, $currentTables);
|
||||||
$tables[$Object->$class->table] = $this->__columns($Object->$class);
|
$tables[$withTable] = $this->__columns($Object->$class);
|
||||||
$tables[$Object->$class->table]['indexes'] = $db->index($Object->$class);
|
$tables[$withTable]['indexes'] = $db->index($Object->$class);
|
||||||
$tables[$Object->$class->table]['tableParameters'] = $db->readTableParameters($table);
|
$tables[$withTable]['tableParameters'] = $db->readTableParameters($withTable);
|
||||||
unset($currentTables[$key]);
|
unset($currentTables[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,6 +448,33 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SchemaPrefixAuthUser class
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases.libs.model
|
||||||
|
*/
|
||||||
|
class SchemaPrefixAuthUser extends CakeTestModel {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $name = 'SchemaPrefixAuthUser';
|
||||||
|
/**
|
||||||
|
* table prefix
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $tablePrefix = 'auth_';
|
||||||
|
/**
|
||||||
|
* useTable
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $useTable = 'users';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CakeSchemaTest
|
* CakeSchemaTest
|
||||||
*
|
*
|
||||||
|
@ -523,7 +550,6 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
|
|
||||||
$expected = array('comments', 'datatypes', 'posts', 'posts_tags', 'tags');
|
$expected = array('comments', 'datatypes', 'posts', 'posts_tags', 'tags');
|
||||||
$this->assertEqual(array_keys($read['tables']), $expected);
|
$this->assertEqual(array_keys($read['tables']), $expected);
|
||||||
|
|
||||||
foreach ($read['tables'] as $table => $fields) {
|
foreach ($read['tables'] as $table => $fields) {
|
||||||
$this->assertEqual(array_keys($fields), array_keys($this->Schema->tables[$table]));
|
$this->assertEqual(array_keys($fields), array_keys($this->Schema->tables[$table]));
|
||||||
}
|
}
|
||||||
|
@ -551,6 +577,25 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s');
|
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test read() with tablePrefix properties.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testSchemaReadWithTablePrefix() {
|
||||||
|
$model =& new SchemaPrefixAuthUser();
|
||||||
|
|
||||||
|
$Schema =& new CakeSchema();
|
||||||
|
$read = $Schema->read(array(
|
||||||
|
'connection' => 'test_suite',
|
||||||
|
'name' => 'TestApp',
|
||||||
|
'models' => array('SchemaPrefixAuthUser')
|
||||||
|
));
|
||||||
|
unset($read['tables']['missing']);
|
||||||
|
$this->assertTrue(isset($read['tables']['auth_users']), 'auth_users key missing %s');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test reading schema from plugins.
|
* test reading schema from plugins.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue