mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing habtm joins for tables with two uuid fields, no primary key and a defined join model. Adding fixtures.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7953 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0c29a7e1b1
commit
b063f22f31
5 changed files with 217 additions and 3 deletions
|
@ -714,12 +714,12 @@ class Model extends Overloadable {
|
|||
'table' => $this->{$type}[$assocKey]['joinTable'],
|
||||
'ds' => $this->useDbConfig
|
||||
));
|
||||
} else {
|
||||
} else {
|
||||
$this->__constructLinkedModel($joinClass, $plugin . $joinClass);
|
||||
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
|
||||
}
|
||||
|
||||
if (count($this->{$joinClass}->schema()) <= 2) {
|
||||
if (count($this->{$joinClass}->schema()) <= 2 && $this->{$joinClass}->primaryKey !== false) {
|
||||
$this->{$joinClass}->primaryKey = $this->{$type}[$assocKey]['foreignKey'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ class ModelTest extends CakeTestCase {
|
|||
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
|
||||
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
|
||||
'core.counter_cache_user', 'core.counter_cache_post', 'core.uuidportfolio',
|
||||
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid'
|
||||
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid',
|
||||
'core.fruit', 'core.fruits_uuid_tag', 'core.uuid_tag'
|
||||
);
|
||||
/**
|
||||
* start method
|
||||
|
@ -310,6 +311,29 @@ class ModelTest extends CakeTestCase {
|
|||
$result = $TestModel->read(null, $id);
|
||||
$this->assertEqual(1, count($result['Uuiditem']));
|
||||
}
|
||||
/**
|
||||
* test HABTM saving when join table has no primary key and only 2 columns.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testHabtmSavingWithNoPrimaryKeyUuidJoinTable() {
|
||||
$this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag');
|
||||
$Fruit =& new Fruit();
|
||||
$data = array(
|
||||
'Fruit' => array(
|
||||
'color' => 'Red',
|
||||
'shape' => 'Heart-shaped',
|
||||
'taste' => 'sweet',
|
||||
'name' => 'Strawberry',
|
||||
),
|
||||
'UuidTag' => array(
|
||||
'UuidTag' => array(
|
||||
'481fc6d0-b920-43e0-e50f-6d1740cf8569'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertTrue($Fruit->save($data));
|
||||
}
|
||||
/**
|
||||
* testHabtmUuidWithNumericId method
|
||||
*
|
||||
|
|
64
cake/tests/fixtures/fruit_fixture.php
vendored
Normal file
64
cake/tests/fixtures/fruit_fixture.php
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?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.7953
|
||||
* @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 FruitFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Fruit'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Fruit';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => 255),
|
||||
'color' => array('type' => 'string', 'length' => 13),
|
||||
'shape' => array('type' => 'string', 'length' => 255),
|
||||
'taste' => array('type' => 'string', 'length' => 255)
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('id' => '481fc6d0-b920-43e0-a40d-6d1740cf8569', 'name' => 'Orange', 'color' => 'orange', 'shape' => 'Spherical', 'taste' => 'Tangy & Sweet')
|
||||
);
|
||||
}
|
||||
?>
|
64
cake/tests/fixtures/fruits_uuid_tag_fixture.php
vendored
Normal file
64
cake/tests/fixtures/fruits_uuid_tag_fixture.php
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?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.7953
|
||||
* @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 FruitsUuidTagFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'FruitsUuidTag'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'FruitsUuidTag';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'fruit_id' => array('type' => 'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
|
||||
'uuid_tag_id' => array('type' => 'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
|
||||
'indexes' => array(
|
||||
'unique_fruits_tags' => array('unique' => true, 'column' => array('fruit_id', 'uuid_tag_id')),
|
||||
),
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('fruit_id' => '481fc6d0-b920-43e0-a40d-6d1740cf8569', 'uuid_tag_id' => '481fc6d0-b920-43e0-e50f-6d1740cf8569')
|
||||
);
|
||||
}
|
||||
?>
|
62
cake/tests/fixtures/uuid_tag_fixture.php
vendored
Normal file
62
cake/tests/fixtures/uuid_tag_fixture.php
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?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.7953
|
||||
* @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 UuidTagFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'UuidTag'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'UuidTag';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => 255),
|
||||
'created' => array('type' => 'datetime')
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('id' => '481fc6d0-b920-43e0-e50f-6d1740cf8569', 'name' => 'MyTag', 'created' => '2009-12-09 12:30:00')
|
||||
);
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue