Permalink
Browse files

Fixing issues with getting values from habtm data after form posting …

…and validation has failed.

Tests added.
Refs #279
  • Loading branch information...
1 parent adaa2b6 commit f0628d100b04fee67f6e0dc392c08145003ed423 @markstory markstory committed Nov 10, 2009
Showing with 23 additions and 1 deletion.
  1. +3 −1 cake/libs/view/helper.php
  2. +20 −0 cake/tests/cases/libs/view/helper.test.php
View
4 cake/libs/view/helper.php
@@ -646,7 +646,9 @@ function value($options = array(), $field = null, $key = 'value') {
}
$habtmKey = $this->field();
- if (empty($result) && isset($this->data[$habtmKey]) && is_array($this->data[$habtmKey])) {
+ if (empty($result) && isset($this->data[$habtmKey][$habtmKey])) {
+ $result = $this->data[$habtmKey][$habtmKey];
+ } elseif (empty($result) && isset($this->data[$habtmKey]) && is_array($this->data[$habtmKey])) {
if (ClassRegistry::isKeySet($habtmKey)) {
$model =& ClassRegistry::getObject($habtmKey);
$result = $this->__selectedArray($this->data[$habtmKey], $model->primaryKey);
View
20 cake/tests/cases/libs/view/helper.test.php
@@ -367,6 +367,26 @@ function testValue() {
$this->Helper->setEntity('Post.2.created.year');
$result = $this->Helper->value('Post.2.created.year');
$this->assertEqual($result, '2008');
+
+ $this->Helper->data = array('HelperTestTag' => array('HelperTestTag' => ''));
+ $this->Helper->setEntity('HelperTestTag.HelperTestTag');
+ $result = $this->Helper->value('HelperTestTag.HelperTestTag');
+ $this->assertEqual($result, '');
+
+ $this->Helper->data = array('HelperTestTag' => array('HelperTestTag' => array(2, 3, 4)));
+ $this->Helper->setEntity('HelperTestTag.HelperTestTag');
+ $result = $this->Helper->value('HelperTestTag.HelperTestTag');
+ $this->assertEqual($result, array(2, 3, 4));
+
+ $this->Helper->data = array(
+ 'HelperTestTag' => array(
+ array('id' => 3),
+ array('id' => 5)
+ )
+ );
+ $this->Helper->setEntity('HelperTestTag.HelperTestTag');
+ $result = $this->Helper->value('HelperTestTag.HelperTestTag');
+ $this->assertEqual($result, array(3 => 3, 5 => 5));
}
/**

0 comments on commit f0628d1

Please sign in to comment.