mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Field type improperly and unnecessarily checked for HABTM inserts. Fixes #5718
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7855 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
fde0d21053
commit
6dc11420ee
4 changed files with 114 additions and 14 deletions
|
@ -1267,8 +1267,8 @@ class Model extends Overloadable {
|
||||||
$newData = $newValues = array();
|
$newData = $newValues = array();
|
||||||
|
|
||||||
foreach ((array)$data as $row) {
|
foreach ((array)$data as $row) {
|
||||||
if (($isUUID && (strlen($row) == 36 || strlen($row) == 16)) || is_numeric($row)) {
|
if ((is_string($row) && (strlen($row) == 36 || strlen($row) == 16)) || is_numeric($row)) {
|
||||||
$values = array(
|
$values = array(
|
||||||
$db->value($id, $this->getColumnType($this->primaryKey)),
|
$db->value($id, $this->getColumnType($this->primaryKey)),
|
||||||
$db->value($row)
|
$db->value($row)
|
||||||
);
|
);
|
||||||
|
@ -1278,7 +1278,7 @@ class Model extends Overloadable {
|
||||||
$values = join(',', $values);
|
$values = join(',', $values);
|
||||||
$newValues[] = "({$values})";
|
$newValues[] = "({$values})";
|
||||||
unset($values);
|
unset($values);
|
||||||
} else if (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
} elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||||
$newData[] = $row;
|
$newData[] = $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ class ModelTest extends CakeTestCase {
|
||||||
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
|
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
|
||||||
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
|
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
|
||||||
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
|
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
|
||||||
'core.uuidportfolio', 'core.uuiditems_uuidportfolio'
|
'core.uuidportfolio', 'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid'
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* start method
|
* start method
|
||||||
|
@ -269,23 +269,41 @@ class ModelTest extends CakeTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testHabtmUuidWithId method
|
* testHabtmUuidWithUuidId method
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testHabtmUuidWithId() {
|
function testHabtmUuidWithUuidId() {
|
||||||
$this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio');
|
$this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio');
|
||||||
$Uuidportfolio =& new Uuidportfolio();
|
$TestModel =& new Uuidportfolio();
|
||||||
|
|
||||||
$uuidportfolio = array('Uuidportfolio' => array('name' => 'Portfolio 3'));
|
$data = array('Uuidportfolio' => array('name' => 'Portfolio 3'));
|
||||||
$uuidportfolio['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569');
|
$data['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569');
|
||||||
$Uuidportfolio->create($uuidportfolio);
|
$TestModel->create($data);
|
||||||
$Uuidportfolio->save();
|
$TestModel->save();
|
||||||
$id = $Uuidportfolio->id;
|
$id = $TestModel->id;
|
||||||
$result = $Uuidportfolio->read(null, $id);
|
$result = $TestModel->read(null, $id);
|
||||||
$this->assertEqual(1, count($result['Uuiditem']));
|
$this->assertEqual(1, count($result['Uuiditem']));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* testHabtmUuidWithNumericId method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testHabtmUuidWithNumericId() {
|
||||||
|
$this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolioNumericid');
|
||||||
|
$TestModel =& new Uuiditem();
|
||||||
|
|
||||||
|
$data = array('Uuiditem' => array('name' => 'Item 7'));
|
||||||
|
$data['Uuidportfolio']['Uuidportfolio'] = array('480af662-eb8c-47d3-886b-230540cf8569');
|
||||||
|
$TestModel->create($data);
|
||||||
|
$TestModel->save();
|
||||||
|
$id = $TestModel->id;
|
||||||
|
$result = $TestModel->read(null, $id);
|
||||||
|
$this->assertEqual(1, count($result['Uuidportfolio']));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* testHabtmFinderQuery method
|
* testHabtmFinderQuery method
|
||||||
*
|
*
|
||||||
|
|
|
@ -2528,7 +2528,9 @@ class Uuiditem extends CakeTestModel {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
//var $hasAndBelongsToMany = array('Uuidportfolio' => array('unique' => true));
|
//var $hasAndBelongsToMany = array('Uuidportfolio' => array('unique' => true));
|
||||||
var $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolio'));
|
// var $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolio'));
|
||||||
|
var $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolioNumericid'));
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* UuiditemsPortfolio class
|
* UuiditemsPortfolio class
|
||||||
|
@ -2545,6 +2547,21 @@ class UuiditemsUuidportfolio extends CakeTestModel {
|
||||||
*/
|
*/
|
||||||
var $name = 'UuiditemsUuidportfolio';
|
var $name = 'UuiditemsUuidportfolio';
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* UuiditemsPortfolioNumericid class
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.cases.libs.model
|
||||||
|
*/
|
||||||
|
class UuiditemsUuidportfolioNumericid extends CakeTestModel {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'UuiditemsUuidportfolioNumericid';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* TranslateTestModel class.
|
* TranslateTestModel class.
|
||||||
*
|
*
|
||||||
|
|
65
cake/tests/fixtures/uuiditems_uuidportfolio_numericid_fixture.php
vendored
Normal file
65
cake/tests/fixtures/uuiditems_uuidportfolio_numericid_fixture.php
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id:$ */
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The Open Group Test Suite License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
* @since CakePHP(tm) v 1.2.0.4667
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
*/
|
||||||
|
class UuiditemsUuidportfolioNumericidFixture extends CakeTestFixture {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'UuiditemsUuidportfolioNumericid'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'UuiditemsUuidportfolioNumericid';
|
||||||
|
/**
|
||||||
|
* fields property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $fields = array(
|
||||||
|
'id' => array('type' => 'integer', 'length' => 10, 'key' => 'primary'),
|
||||||
|
'uuiditem_id' => array('type' => 'string', 'length' => 36, 'null' => false),
|
||||||
|
'uuidportfolio_id' => array('type' => 'string', 'length' => 36, 'null' => false)
|
||||||
|
);
|
||||||
|
/**
|
||||||
|
* records property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $records = array(
|
||||||
|
array('id' => 1, 'uuiditem_id' => '481fc6d0-b920-43e0-a40d-6d1740cf8569', 'uuidportfolio_id' => '4806e091-6940-4d2b-b227-303740cf8569'),
|
||||||
|
array('id' => 2, 'uuiditem_id' => '48298a29-81c0-4c26-a7fb-413140cf8569', 'uuidportfolio_id' => '480af662-eb8c-47d3-886b-230540cf8569'),
|
||||||
|
array('id' => 3, 'uuiditem_id' => '482b7756-8da0-419a-b21f-27da40cf8569', 'uuidportfolio_id' => '4806e091-6940-4d2b-b227-303740cf8569'),
|
||||||
|
array('id' => 4, 'uuiditem_id' => '482cfd4b-0e7c-4ea3-9582-4cec40cf8569', 'uuidportfolio_id' => '4806e091-6940-4d2b-b227-303740cf8569')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in a new issue