mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Adding fix for scaffold when using self associated HABTM
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4759 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0d373a0c16
commit
49e58cec49
3 changed files with 91 additions and 89 deletions
|
@ -812,17 +812,17 @@ class Controller extends Object {
|
||||||
$otherModelKey = Inflector::underscore($assocData['className']);
|
$otherModelKey = Inflector::underscore($assocData['className']);
|
||||||
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
|
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
|
||||||
if ($doCreateOptions) {
|
if ($doCreateOptions) {
|
||||||
$fieldNames[$otherModelKey]['model'] = $associationName;
|
$fieldNames[$associationName]['model'] = $associationName;
|
||||||
$fieldNames[$otherModelKey]['label'] = "Related " . Inflector::humanize(Inflector::pluralize($associationName));
|
$fieldNames[$associationName]['label'] = "Related " . Inflector::humanize(Inflector::pluralize($associationName));
|
||||||
$fieldNames[$otherModelKey]['prompt'] = $fieldNames[$otherModelKey]['label'];
|
$fieldNames[$associationName]['prompt'] = $fieldNames[$associationName]['label'];
|
||||||
$fieldNames[$otherModelKey]['type'] = "select";
|
$fieldNames[$associationName]['type'] = "select";
|
||||||
$fieldNames[$otherModelKey]['multiple'] = "multiple";
|
$fieldNames[$associationName]['multiple'] = "multiple";
|
||||||
$fieldNames[$otherModelKey]['tagName'] = $associationName . '/' . $associationName;
|
$fieldNames[$associationName]['tagName'] = $associationName . '/' . $associationName;
|
||||||
$fieldNames[$otherModelKey]['name'] = $associationName;
|
$fieldNames[$associationName]['name'] = $associationName;
|
||||||
$fieldNames[$otherModelKey]['class'] = 'optional';
|
$fieldNames[$associationName]['class'] = 'optional';
|
||||||
$fieldNames[$otherModelKey]['options'] = $otherModelObj->generateList();
|
$fieldNames[$associationName]['options'] = $otherModelObj->generateList();
|
||||||
if (isset($data[$associationName])) {
|
if (isset($data[$associationName])) {
|
||||||
$fieldNames[$otherModelKey]['selected'] = $this->_selectedArray($data[$associationName], $otherModelObj->primaryKey);
|
$fieldNames[$associationName]['selected'] = $this->_selectedArray($data[$associationName], $otherModelObj->primaryKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ class DboSource extends DataSource {
|
||||||
if (isset($params[2 + $off])) {
|
if (isset($params[2 + $off])) {
|
||||||
$order = $params[2 + $off];
|
$order = $params[2 + $off];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!array_key_exists(0, $params)) {
|
if(!array_key_exists(0, $params)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,9 +119,9 @@
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'ArticleFeatured'=> array('className' => 'ArticleFeatured'),
|
'ArticleFeatured'=> array('className' => 'ArticleFeatured'),
|
||||||
'Category'=> array('className' => 'Category')
|
'Category'=> array('className' => 'Category')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
*
|
*
|
||||||
|
@ -682,9 +682,9 @@ class ModelTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Featured = new Featured();
|
$this->Featured = new Featured();
|
||||||
|
|
||||||
$this->Featured->recursive = 2;
|
$this->Featured->recursive = 2;
|
||||||
$this->Featured->bindModel(array(
|
$this->Featured->bindModel(array(
|
||||||
'belongsTo' => array(
|
'belongsTo' => array(
|
||||||
|
@ -694,103 +694,105 @@ class ModelTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->Featured->ArticleFeatured->unbindModel(array(
|
$this->Featured->ArticleFeatured->unbindModel(array(
|
||||||
'hasMany' => array('Attachment', 'Comment'),
|
'hasMany' => array('Attachment', 'Comment'),
|
||||||
'hasAndBelongsToMany'=>array('Tag'))
|
'hasAndBelongsToMany'=>array('Tag'))
|
||||||
);
|
);
|
||||||
|
|
||||||
// UNCOMMENT THE FOLLOWING LINE TO MAKE TEST SUCCEED:
|
// UNCOMMENT THE FOLLOWING LINE TO MAKE TEST SUCCEED:
|
||||||
//
|
//
|
||||||
// $this->Featured->ArticleFeatured->unbindModel(array('belongsTo'=>array('Category')));
|
// $this->Featured->ArticleFeatured->unbindModel(array('belongsTo'=>array('Category')));
|
||||||
|
|
||||||
$orderBy = 'ArticleFeatured.id ASC';
|
$orderBy = 'ArticleFeatured.id ASC';
|
||||||
$result = $this->Featured->findAll(null, null, $orderBy, 3);
|
$result = $this->Featured->findAll(null, null, $orderBy, 3);
|
||||||
|
|
||||||
$expected = array (
|
$expected = array (
|
||||||
array (
|
array (
|
||||||
'Featured' => array (
|
'Featured' => array (
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'article_featured_id' => '1',
|
'article_featured_id' => '1',
|
||||||
'category_id' => '1',
|
'category_id' => '1',
|
||||||
'published_date' => '2007-03-31 10:39:23',
|
'published_date' => '2007-03-31 10:39:23',
|
||||||
'end_date' => '2007-05-15 10:39:23',
|
'end_date' => '2007-05-15 10:39:23',
|
||||||
'created' => '2007-03-18 10:39:23',
|
'created' => '2007-03-18 10:39:23',
|
||||||
'updated' => '2007-03-18 10:41:31'
|
'updated' => '2007-03-18 10:41:31'
|
||||||
),
|
),
|
||||||
'ArticleFeatured' => array (
|
'ArticleFeatured' => array (
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'title' => 'First Article',
|
'title' => 'First Article',
|
||||||
'user_id' => '1',
|
'user_id' => '1',
|
||||||
'published' => 'Y',
|
'published' => 'Y',
|
||||||
'User' => array (
|
'User' => array (
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'user' => 'mariano',
|
'user' => 'mariano',
|
||||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||||
'created' => '2007-03-17 01:16:23',
|
'created' => '2007-03-17 01:16:23',
|
||||||
'updated' => '2007-03-17 01:18:31'
|
'updated' => '2007-03-17 01:18:31'
|
||||||
),
|
),
|
||||||
'Featured' => array (
|
'Featured' => array (
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'article_featured_id' => '1',
|
'article_featured_id' => '1',
|
||||||
'category_id' => '1',
|
'category_id' => '1',
|
||||||
'published_date' => '2007-03-31 10:39:23',
|
'published_date' => '2007-03-31 10:39:23',
|
||||||
'end_date' => '2007-05-15 10:39:23',
|
'end_date' => '2007-05-15 10:39:23',
|
||||||
'created' => '2007-03-18 10:39:23',
|
'created' => '2007-03-18 10:39:23',
|
||||||
'updated' => '2007-03-18 10:41:31'
|
'updated' => '2007-03-18 10:41:31'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'Category' => array (
|
'Category' => array (
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'parent_id' => '0',
|
'parent_id' => '0',
|
||||||
'name' => 'Category 1',
|
'name' => 'Category 1',
|
||||||
'created' => '2007-03-18 15:30:23',
|
'created' => '2007-03-18 15:30:23',
|
||||||
'updated' => '2007-03-18 15:32:31'
|
'updated' => '2007-03-18 15:32:31'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'Featured' => array (
|
'Featured' => array (
|
||||||
'id' => '2',
|
'id' => '2',
|
||||||
'article_featured_id' => '2',
|
'article_featured_id' => '2',
|
||||||
'category_id' => '1',
|
'category_id' => '1',
|
||||||
'published_date' => '2007-03-31 10:39:23',
|
'published_date' => '2007-03-31 10:39:23',
|
||||||
'end_date' => '2007-05-15 10:39:23',
|
'end_date' => '2007-05-15 10:39:23',
|
||||||
'created' => '2007-03-18 10:39:23',
|
'created' => '2007-03-18 10:39:23',
|
||||||
'updated' => '2007-03-18 10:41:31'
|
'updated' => '2007-03-18 10:41:31'
|
||||||
),
|
),
|
||||||
'ArticleFeatured' => array (
|
'ArticleFeatured' => array (
|
||||||
'id' => '2',
|
'id' => '2',
|
||||||
'title' => 'Second Article',
|
'title' => 'Second Article',
|
||||||
'user_id' => '3',
|
'user_id' => '3',
|
||||||
'published' => 'Y',
|
'published' => 'Y',
|
||||||
'User' => array (
|
'User' => array (
|
||||||
'id' => '3',
|
'id' => '3',
|
||||||
'user' => 'larry',
|
'user' => 'larry',
|
||||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||||
'created' => '2007-03-17 01:20:23',
|
'created' => '2007-03-17 01:20:23',
|
||||||
'updated' => '2007-03-17 01:22:31'
|
'updated' => '2007-03-17 01:22:31'
|
||||||
),
|
),
|
||||||
'Featured' => array (
|
'Featured' => array (
|
||||||
'id' => '2',
|
'id' => '2',
|
||||||
'article_featured_id' => '2',
|
'article_featured_id' => '2',
|
||||||
'category_id' => '1',
|
'category_id' => '1',
|
||||||
'published_date' => '2007-03-31 10:39:23',
|
'published_date' => '2007-03-31 10:39:23',
|
||||||
'end_date' => '2007-05-15 10:39:23',
|
'end_date' => '2007-05-15 10:39:23',
|
||||||
'created' => '2007-03-18 10:39:23',
|
'created' => '2007-03-18 10:39:23',
|
||||||
'updated' => '2007-03-18 10:41:31'
|
'updated' => '2007-03-18 10:41:31'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'Category' => array (
|
'Category' => array (
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'parent_id' => '0',
|
'parent_id' => '0',
|
||||||
'name' => 'Category 1',
|
'name' => 'Category 1',
|
||||||
'created' => '2007-03-18 15:30:23',
|
'created' => '2007-03-18 15:30:23',
|
||||||
'updated' => '2007-03-18 15:32:31'
|
'updated' => '2007-03-18 15:32:31'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
debug($result);
|
||||||
|
debug($expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSaveField() {
|
function testSaveField() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue