Fixing Helper::value() and extraction of habtm data. Refs #256

This commit is contained in:
mark_story 2009-11-04 14:05:12 -05:00
parent b974127562
commit 380b49a446
2 changed files with 13 additions and 5 deletions

View file

@ -544,7 +544,7 @@ class Helper extends Overloadable {
$errors = $this->validationErrors; $errors = $this->validationErrors;
$entity = $view->entity(); $entity = $view->entity();
if (!empty($entity)) { if (!empty($entity)) {
return Set::extract($errors,join('.',$entity)); return Set::extract($errors, join('.', $entity));
} }
} }
@ -648,7 +648,15 @@ class Helper extends Overloadable {
$entity = $view->entity(); $entity = $view->entity();
if (!empty($this->data) && !empty($entity)) { if (!empty($this->data) && !empty($entity)) {
$result = Set::extract($this->data,join('.',$entity)); $result = Set::extract($this->data, join('.', $entity));
}
$habtmKey = $this->field();
if (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);
}
} }
if (is_array($result)) { if (is_array($result)) {

View file

@ -538,11 +538,11 @@ class HelperTest extends CakeTestCase {
*/ */
function testMulitDimensionValue() { function testMulitDimensionValue() {
$this->Helper->data = array(); $this->Helper->data = array();
for($i = 0; $i < 2; $i++) { for ($i = 0; $i < 2; $i++) {
$this->Helper->data['Model'][$i] = 'what'; $this->Helper->data['Model'][$i] = 'what';
$result[] = $this->Helper->value("Model.{$i}"); $result[] = $this->Helper->value("Model.{$i}");
$this->Helper->data['Model'][$i] = array(); $this->Helper->data['Model'][$i] = array();
for($j = 0; $j < 2; $j++) { for ($j = 0; $j < 2; $j++) {
$this->Helper->data['Model'][$i][$j] = 'how'; $this->Helper->data['Model'][$i][$j] = 'how';
$result[] = $this->Helper->value("Model.{$i}.{$j}"); $result[] = $this->Helper->value("Model.{$i}.{$j}");
} }