Adding fix for join table using UUID's as the primary key.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7775 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-10-23 13:29:32 +00:00
parent 16e2579f01
commit d3896854f5
3 changed files with 99 additions and 5 deletions

View file

@ -1233,6 +1233,9 @@ class Model extends Overloadable {
);
}
$isUUID = !empty($this->{$join}->primaryKey) && (($this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'string' && $this->{$join}->_schema[$this->{$join}->primaryKey]['length'] === 36)
|| ($this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'binary' && $this->{$join}->_schema[$this->{$join}->primaryKey]['length'] === 16));
foreach ($value as $update) {
if (!empty($update)) {
if (is_array($update)) {
@ -1240,10 +1243,14 @@ class Model extends Overloadable {
$this->{$join}->create($update);
$this->{$join}->save();
} elseif (!in_array($update, $links)) {
$values = join(',', array(
$values = array(
$db->value($id, $this->getColumnType($this->primaryKey)),
$db->value($update)
));
);
if ($isUUID) {
$values[] = $db->value(String::uuid());
}
$values = join(',', $values);
$newValues[] = "({$values})";
unset($values);
}
@ -1251,10 +1258,15 @@ class Model extends Overloadable {
}
if (!empty($newValues)) {
$fields = join(',', array(
$fields = array(
$db->name($this->hasAndBelongsToMany[$assoc]['foreignKey']),
$db->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey'])
));
);
if ($isUUID) {
$fields[] = $db->name($this->{$join}->primaryKey);
}
$fields = join(',', $fields);
$db->insertMulti($this->{$join}, $fields, $newValues);
}
}

View file

@ -61,7 +61,7 @@ class ModelTest extends CakeTestCase {
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c',
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field',
'core.node', 'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.overall_favorite', 'core.account',
'core.content', 'core.content_account', 'core.film_file', 'core.basket', 'core.test_plugin_article', 'core.test_plugin_comment'
'core.content', 'core.content_account', 'core.film_file', 'core.basket', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem', 'core.uuidportfolio', 'core.uuiditems_uuidportfolio'
);
/**
* start method
@ -249,6 +249,24 @@ class ModelTest extends CakeTestCase {
'Image' => array()))));
$this->assertEqual($result, $expected);
}
/**
* testHabtmUuidWithId method
*
* @access public
* @return void
*/
function testHabtmUuidWithId() {
$this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio');
$Uuidportfolio =& new Uuidportfolio();
$uuidportfolio = array('Uuidportfolio' => array('name' => 'Portfolio 3'));
$uuidportfolio['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569');
$Uuidportfolio->create($uuidportfolio);
$Uuidportfolio->save();
$id = $Uuidportfolio->id;
$result = $Uuidportfolio->read(null, $id);
$this->assertEqual(1, count($result['Uuiditem']));
}
/**
* testHabtmFinderQuery method
*
@ -782,6 +800,10 @@ class ModelTest extends CakeTestCase {
} else {
$intLength = 11;
}
foreach (array('collate', 'charset') as $type) {
unset($result['user'][$type]);
unset($result['password'][$type]);
}
$expected = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => $intLength, 'key' => 'primary'),

View file

@ -2487,4 +2487,64 @@ class TestPluginComment extends CakeTestModel {
'User'
);
}
/**
* Uuidportfolio class
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class Uuidportfolio extends CakeTestModel {
/**
* name property
*
* @var string 'Uuidportfolio'
* @access public
*/
var $name = 'Uuidportfolio';
/**
* hasAndBelongsToMany property
*
* @var array
* @access public
*/
var $hasAndBelongsToMany = array('Uuiditem');
}
/**
* Uuiditem class
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class Uuiditem extends CakeTestModel {
/**
* name property
*
* @var string 'Item'
* @access public
*/
var $name = 'Uuiditem';
/**
* hasAndBelongsToMany property
*
* @var array
* @access public
*/
//var $hasAndBelongsToMany = array('Uuidportfolio' => array('unique' => true));
var $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolio'));
}
/**
* UuiditemsPortfolio class
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class UuiditemsUuidportfolio extends CakeTestModel {
/**
* name property
*
* @var string 'ItemsPortfolio'
* @access public
*/
var $name = 'UuiditemsUuidportfolio';
}
?>