mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding fix when join table does not have a primary key 'id' defined
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7918 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
24cc66b43e
commit
0d3ea7a5f2
3 changed files with 55 additions and 2 deletions
|
@ -719,7 +719,7 @@ class Model extends Overloadable {
|
|||
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
|
||||
}
|
||||
|
||||
if ($this->{$joinClass}->primaryKey == 'id' && count($this->{$joinClass}->schema()) <= 2) {
|
||||
if (count($this->{$joinClass}->schema()) <= 2) {
|
||||
$this->{$joinClass}->primaryKey = $this->{$type}[$assocKey]['foreignKey'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6238,6 +6238,35 @@ class ModelTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testDeleteArticleBLinks() {
|
||||
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
||||
$TestModel =& new ArticleB();
|
||||
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testPkInHabtmLinkModelArticleB() {
|
||||
$this->loadFixtures('Article', 'Tag');
|
||||
$TestModel2 =& new ArticleB();
|
||||
$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
|
||||
}
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
|
|
|
@ -2839,4 +2839,28 @@ class TranslatedArticle extends CakeTestModel {
|
|||
*/
|
||||
var $belongsTo = array('User');
|
||||
}
|
||||
?>
|
||||
|
||||
class ArticleB extends CakeTestModel {
|
||||
var $name = 'ArticleB';
|
||||
var $useTable = 'articles';
|
||||
var $hasAndBelongsToMany = array(
|
||||
'TagB' => array(
|
||||
'className' => 'TagB',
|
||||
'joinTable' => 'articles_tags',
|
||||
'foreignKey' => 'article_id',
|
||||
'associationForeignKey' => 'tag_id')
|
||||
);
|
||||
}
|
||||
|
||||
class TagB extends CakeTestModel {
|
||||
var $name = 'TagB';
|
||||
var $useTable = 'tags';
|
||||
var $hasAndBelongsToMany = array(
|
||||
'ArticleB' => array(
|
||||
'className' => 'ArticleB',
|
||||
'joinTable' => 'articles_tags',
|
||||
'foreignKey' => 'tag_id',
|
||||
'associationForeignKey' => 'article_id')
|
||||
);
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue