"Fixes #4256, tablePrefix + HABTM with defaults == wrong joinTable"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6585 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-03-16 07:18:42 +00:00
parent aac0cecf49
commit 1b4c445cad
4 changed files with 33 additions and 8 deletions

View file

@ -127,7 +127,12 @@ class ClassRegistry {
if (App::import($type, $plugin . $class)) {
${$class} =& new $class($options);
} elseif ($type === 'Model') {
${$class} =& new AppModel($options);
if ($plugin && class_exists($plugin .'AppModel')) {
$appModel = $plugin .'AppModel';
} else {
$appModel = 'AppModel';
}
${$class} =& new $appModel($options);
}
if (!isset(${$class})) {

View file

@ -1035,23 +1035,26 @@ class DboSource extends DataSource {
);
break;
case 'hasAndBelongsToMany':
$joinTbl = $this->fullTableName($assocData['joinTable']);
$joinFields = array();
$joinAssoc = null;
$joinAlias = $joinTbl;
if (isset($assocData['with']) && !empty($assocData['with'])) {
$joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']);
list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys);
$joinTbl = $this->fullTableName($model->{$with});
$joinAlias = $joinTbl;
if (is_array($joinFields) && !empty($joinFields)) {
$joinFields = $this->fields($model->{$with}, $model->{$with}->alias, $joinFields);
$joinAssoc = $joinAlias = $model->{$with}->alias;
} else {
$joinFields = array();
}
} else {
$joinTbl = $this->fullTableName($assocData['joinTable']);
$joinAlias = $joinTbl;
}
$query = array(
'conditions' => $assocData['conditions'],
'limit' => $assocData['limit'],
@ -1062,9 +1065,7 @@ class DboSource extends DataSource {
'joins' => array(array(
'table' => $joinTbl,
'alias' => $joinAssoc,
'conditions' => $this->getConstraint('hasAndBelongsToMany', $model, $linkModel, $joinAlias, $assocData, $alias)
))
);
'conditions' => $this->getConstraint('hasAndBelongsToMany', $model, $linkModel, $joinAlias, $assocData, $alias))));
break;
}
if (isset($query)) {

View file

@ -992,7 +992,7 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual($result, $expected);
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php';
unlink($filename);
$url = 'TestCachedPages/index';
restore_error_handler();

View file

@ -42,7 +42,16 @@ class RegisterArticleTag extends ClassRegisterModel {
var $name = 'RegisterArticlTag';
}
class RegistryPluginAppModel extends ClassRegisterModel {
var $tablePrefix = 'something_';
}
class TestRegistryPluginModel extends RegistryPluginAppModel {
var $name = 'TestRegistryPluginModel';
}
class ClassRegistryTest extends UnitTestCase {
function testAddModel() {
if (PHP5) {
$Tag = ClassRegistry::init('RegisterArticleTag');
@ -124,5 +133,15 @@ class ClassRegistryTest extends UnitTestCase {
$Tag = ClassRegistry::getObject('Tag');
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
}
function testPluginAppModel() {
$TestRegistryPluginModel = ClassRegistry::isKeySet('TestRegistryPluginModel');
$this->assertFalse($TestRegistryPluginModel);
$TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel');
$this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel'));
$this->assertEqual($TestRegistryPluginModel->tablePrefix, 'something_');
}
}
?>