mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
closes #5142 primary key on custom join models
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7393 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f97a3f27b0
commit
f6d269a9e0
6 changed files with 357 additions and 35 deletions
|
@ -666,17 +666,13 @@ class Model extends Overloadable {
|
|||
'ds' => $this->useDbConfig
|
||||
));
|
||||
$this->{$joinClass}->primaryKey = $this->{$type}[$assocKey]['foreignKey'];
|
||||
|
||||
} else {
|
||||
$this->__constructLinkedModel($joinClass, $plugin . $joinClass);
|
||||
$this->{$joinClass}->primaryKey = $this->{$type}[$assocKey]['foreignKey'];
|
||||
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
|
||||
}
|
||||
|
||||
if (count($this->{$joinClass}->_schema) > 2) {
|
||||
if (isset($this->{$joinClass}->_schema['id'])) {
|
||||
$this->{$joinClass}->primaryKey = 'id';
|
||||
if (count($this->{$joinClass}->schema()) <= 2) {
|
||||
$this->{$joinClass}->primaryKey = $this->{$type}[$assocKey]['foreignKey'];
|
||||
}
|
||||
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,8 @@ class ModelTest extends CakeTestCase {
|
|||
'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
|
||||
'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.node', 'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.overall_favorite', 'core.account',
|
||||
'core.content', 'core.content_account'
|
||||
);
|
||||
/**
|
||||
* start method
|
||||
|
@ -5335,6 +5336,8 @@ class ModelTest extends CakeTestCase {
|
|||
'day' => '1', 'month' => '1', 'year' => '2008'
|
||||
),
|
||||
'title' => 'Test Title',
|
||||
// schreck - Jul 30, 2008 - should this be set to something else?
|
||||
'user_id' => 1
|
||||
));
|
||||
$Article->create();
|
||||
$this->assertTrue($Article->save($data));
|
||||
|
@ -5412,6 +5415,28 @@ class ModelTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($TestModel->Comment->validationErrors, $expected);
|
||||
}
|
||||
/**
|
||||
* testPkInHabtmLinkModel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testPkInHabtmLinkModel() {
|
||||
//Test Nonconformant Models
|
||||
$this->loadFixtures('Content', 'ContentAccount', 'Account');
|
||||
$TestModel =& new Content();
|
||||
$this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId');
|
||||
|
||||
//test conformant models with no PK in the join table
|
||||
$this->loadFixtures('Article', 'Tag');
|
||||
$TestModel2 =& new Article();
|
||||
$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
|
||||
|
||||
//test conformant models with PK in join table
|
||||
$this->loadFixtures('Item', 'Portfolio', 'ItemsPortfolio');
|
||||
$TestModel3 =& new Portfolio();
|
||||
$this->assertEqual($TestModel3->ItemsPortfolio->primaryKey, 'id');
|
||||
}
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
|
|
|
@ -2258,4 +2258,98 @@ class Ad extends CakeTestModel {
|
|||
*/
|
||||
var $belongsTo = array('Campaign');
|
||||
}
|
||||
/**
|
||||
* Nonconformant Content class
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Content extends CakeTestModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Content'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Content';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'Content'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'Content';
|
||||
/**
|
||||
* primaryKey property
|
||||
*
|
||||
* @var string 'iContentId'
|
||||
* @access public
|
||||
*/
|
||||
var $primaryKey = 'iContentId';
|
||||
/**
|
||||
* hasAndBelongsToMany property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasAndBelongsToMany = array('Account' => array('className' => 'Account', 'joinTable' => 'ContentAccounts', 'foreignKey' => 'iContentId', 'associationForeignKey', 'iAccountId'));
|
||||
}
|
||||
/**
|
||||
* Nonconformant Account class
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Account extends CakeTestModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Account'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Account';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'Account'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'Accounts';
|
||||
/**
|
||||
* primaryKey property
|
||||
*
|
||||
* @var string 'iAccountId'
|
||||
* @access public
|
||||
*/
|
||||
var $primaryKey = 'iAccountId';
|
||||
}
|
||||
/**
|
||||
* Nonconformant ContentAccount class
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class ContentAccount extends CakeTestModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Account'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ContentAccount';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'Account'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'ContentAccounts';
|
||||
/**
|
||||
* primaryKey property
|
||||
*
|
||||
* @var string 'iAccountId'
|
||||
* @access public
|
||||
*/
|
||||
var $primaryKey = 'iContentAccountsId';
|
||||
}
|
||||
?>
|
68
cake/tests/fixtures/account_fixture.php
vendored
Normal file
68
cake/tests/fixtures/account_fixture.php
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?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.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* 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.
|
||||
* @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 AccountFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Aco'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Account';
|
||||
var $table = 'Accounts';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'iAccountId' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'cDescription' => array('type' => 'string', 'length' => 10, 'null' => true)
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('cDescription' => 'gwoo'),
|
||||
array('cDescription' => 'phpnut'),
|
||||
array('cDescription' => 'schreck'),
|
||||
array('cDescription' => 'dude')
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
71
cake/tests/fixtures/content_account_fixture.php
vendored
Normal file
71
cake/tests/fixtures/content_account_fixture.php
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?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.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* 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.
|
||||
* @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 ContentAccountFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Aco'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ContentAccount';
|
||||
var $table = 'ContentAccounts';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'iContentAccountsId' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'iContentId' => array('type' => 'integer'),
|
||||
'iAccountId' => array('type' => 'integer')
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('iContentId' => 1, 'iAccountId' => 1),
|
||||
array('iContentId' => 2, 'iAccountId' => 2),
|
||||
array('iContentId' => 3, 'iAccountId' => 3),
|
||||
array('iContentId' => 4, 'iAccountId' => 4),
|
||||
array('iContentId' => 1, 'iAccountId' => 2),
|
||||
array('iContentId' => 2, 'iAccountId' => 3),
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
68
cake/tests/fixtures/content_fixture.php
vendored
Normal file
68
cake/tests/fixtures/content_fixture.php
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?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.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* 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.
|
||||
* @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 ContentFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Aco'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Content';
|
||||
var $table = 'Content';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'iContentId' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'cDescription' => array('type' => 'string', 'length' => 50, 'null' => true)
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('cDescription' => 'Test Content 1'),
|
||||
array('cDescription' => 'Test Content 2'),
|
||||
array('cDescription' => 'Test Content 3'),
|
||||
array('cDescription' => 'Test Content 4')
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue