Permalink
Browse files

Fixing habtm joins for tables with two uuid fields, no primary key an…

…d 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
  • Loading branch information...
1 parent 0c29a7e commit b063f22f3133cc3f91dfa3d0f7017179c4e348b3 @markstory markstory committed Dec 23, 2008
@@ -714,12 +714,12 @@ function __generateAssociation($type) {
'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
@@ -311,6 +312,29 @@ function testHabtmUuidWithUuidId() {
$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
*
* @access public
@@ -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')
+ );
+}
+?>
@@ -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')
+ );
+}
+?>
@@ -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')
+ );
+}
+?>

0 comments on commit b063f22

Please sign in to comment.