mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +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']);
|
||||
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
|
||||
if ($doCreateOptions) {
|
||||
$fieldNames[$otherModelKey]['model'] = $associationName;
|
||||
$fieldNames[$otherModelKey]['label'] = "Related " . Inflector::humanize(Inflector::pluralize($associationName));
|
||||
$fieldNames[$otherModelKey]['prompt'] = $fieldNames[$otherModelKey]['label'];
|
||||
$fieldNames[$otherModelKey]['type'] = "select";
|
||||
$fieldNames[$otherModelKey]['multiple'] = "multiple";
|
||||
$fieldNames[$otherModelKey]['tagName'] = $associationName . '/' . $associationName;
|
||||
$fieldNames[$otherModelKey]['name'] = $associationName;
|
||||
$fieldNames[$otherModelKey]['class'] = 'optional';
|
||||
$fieldNames[$otherModelKey]['options'] = $otherModelObj->generateList();
|
||||
$fieldNames[$associationName]['model'] = $associationName;
|
||||
$fieldNames[$associationName]['label'] = "Related " . Inflector::humanize(Inflector::pluralize($associationName));
|
||||
$fieldNames[$associationName]['prompt'] = $fieldNames[$associationName]['label'];
|
||||
$fieldNames[$associationName]['type'] = "select";
|
||||
$fieldNames[$associationName]['multiple'] = "multiple";
|
||||
$fieldNames[$associationName]['tagName'] = $associationName . '/' . $associationName;
|
||||
$fieldNames[$associationName]['name'] = $associationName;
|
||||
$fieldNames[$associationName]['class'] = 'optional';
|
||||
$fieldNames[$associationName]['options'] = $otherModelObj->generateList();
|
||||
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])) {
|
||||
$order = $params[2 + $off];
|
||||
}
|
||||
|
||||
|
||||
if(!array_key_exists(0, $params)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -119,9 +119,9 @@
|
|||
var $belongsTo = array(
|
||||
'ArticleFeatured'=> array('className' => 'ArticleFeatured'),
|
||||
'Category'=> array('className' => 'Category')
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -682,9 +682,9 @@ class ModelTest extends CakeTestCase {
|
|||
)
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
$this->Featured = new Featured();
|
||||
|
||||
|
||||
$this->Featured->recursive = 2;
|
||||
$this->Featured->bindModel(array(
|
||||
'belongsTo' => array(
|
||||
|
@ -694,103 +694,105 @@ class ModelTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
$this->Featured->ArticleFeatured->unbindModel(array(
|
||||
'hasMany' => array('Attachment', 'Comment'),
|
||||
'hasMany' => array('Attachment', 'Comment'),
|
||||
'hasAndBelongsToMany'=>array('Tag'))
|
||||
);
|
||||
|
||||
|
||||
// UNCOMMENT THE FOLLOWING LINE TO MAKE TEST SUCCEED:
|
||||
//
|
||||
// $this->Featured->ArticleFeatured->unbindModel(array('belongsTo'=>array('Category')));
|
||||
|
||||
|
||||
$orderBy = 'ArticleFeatured.id ASC';
|
||||
$result = $this->Featured->findAll(null, null, $orderBy, 3);
|
||||
|
||||
$expected = array (
|
||||
array (
|
||||
'Featured' => array (
|
||||
'id' => '1',
|
||||
'article_featured_id' => '1',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
|
||||
$expected = array (
|
||||
array (
|
||||
'Featured' => array (
|
||||
'id' => '1',
|
||||
'article_featured_id' => '1',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
),
|
||||
'ArticleFeatured' => array (
|
||||
'id' => '1',
|
||||
'title' => 'First Article',
|
||||
'user_id' => '1',
|
||||
'published' => 'Y',
|
||||
'User' => array (
|
||||
'id' => '1',
|
||||
'user' => 'mariano',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:16:23',
|
||||
),
|
||||
'ArticleFeatured' => array (
|
||||
'id' => '1',
|
||||
'title' => 'First Article',
|
||||
'user_id' => '1',
|
||||
'published' => 'Y',
|
||||
'User' => array (
|
||||
'id' => '1',
|
||||
'user' => 'mariano',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:16:23',
|
||||
'updated' => '2007-03-17 01:18:31'
|
||||
),
|
||||
'Featured' => array (
|
||||
'id' => '1',
|
||||
'article_featured_id' => '1',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
),
|
||||
'Featured' => array (
|
||||
'id' => '1',
|
||||
'article_featured_id' => '1',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
)
|
||||
),
|
||||
'Category' => array (
|
||||
'id' => '1',
|
||||
'parent_id' => '0',
|
||||
'name' => 'Category 1',
|
||||
'created' => '2007-03-18 15:30:23',
|
||||
),
|
||||
'Category' => array (
|
||||
'id' => '1',
|
||||
'parent_id' => '0',
|
||||
'name' => 'Category 1',
|
||||
'created' => '2007-03-18 15:30:23',
|
||||
'updated' => '2007-03-18 15:32:31'
|
||||
)
|
||||
),
|
||||
array (
|
||||
'Featured' => array (
|
||||
'id' => '2',
|
||||
'article_featured_id' => '2',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
),
|
||||
array (
|
||||
'Featured' => array (
|
||||
'id' => '2',
|
||||
'article_featured_id' => '2',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
),
|
||||
'ArticleFeatured' => array (
|
||||
'id' => '2',
|
||||
'title' => 'Second Article',
|
||||
'user_id' => '3',
|
||||
'published' => 'Y',
|
||||
'User' => array (
|
||||
'id' => '3',
|
||||
'user' => 'larry',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:20:23',
|
||||
),
|
||||
'ArticleFeatured' => array (
|
||||
'id' => '2',
|
||||
'title' => 'Second Article',
|
||||
'user_id' => '3',
|
||||
'published' => 'Y',
|
||||
'User' => array (
|
||||
'id' => '3',
|
||||
'user' => 'larry',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:20:23',
|
||||
'updated' => '2007-03-17 01:22:31'
|
||||
),
|
||||
'Featured' => array (
|
||||
'id' => '2',
|
||||
'article_featured_id' => '2',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
),
|
||||
'Featured' => array (
|
||||
'id' => '2',
|
||||
'article_featured_id' => '2',
|
||||
'category_id' => '1',
|
||||
'published_date' => '2007-03-31 10:39:23',
|
||||
'end_date' => '2007-05-15 10:39:23',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
)
|
||||
),
|
||||
'Category' => array (
|
||||
'id' => '1',
|
||||
'parent_id' => '0',
|
||||
'name' => 'Category 1',
|
||||
'created' => '2007-03-18 15:30:23',
|
||||
),
|
||||
'Category' => array (
|
||||
'id' => '1',
|
||||
'parent_id' => '0',
|
||||
'name' => 'Category 1',
|
||||
'created' => '2007-03-18 15:30:23',
|
||||
'updated' => '2007-03-18 15:32:31'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
debug($result);
|
||||
debug($expected);
|
||||
}
|
||||
|
||||
function testSaveField() {
|
||||
|
|
Loading…
Add table
Reference in a new issue