Permalink
Browse files

Fix issue with HABTM fields

habtm fields were not being correctly being detected.
  • Loading branch information...
1 parent d6b978c commit 1743eaa7769d43f2be8bec6bec4ba698131e64fa @markstory markstory committed Sep 9, 2011
Showing with 37 additions and 12 deletions.
  1. +24 −2 lib/Cake/Test/Case/View/HelperTest.php
  2. +13 −10 lib/Cake/View/Helper.php
@@ -304,7 +304,6 @@ public function testSetEntityAssociated() {
$this->assertEquals($expected, $this->Helper->entity());
$this->assertEquals('HelperTestComment', $this->Helper->model());
-
}
/**
@@ -314,7 +313,11 @@ public function testSetEntityAssociated() {
* @return void
*/
public function testSetEntityAssociatedCamelCaseField() {
- $this->Helper->fieldset = array('HelperTestComment' => array('fields' => array('BigField' => 'something')));
+ $this->Helper->fieldset = array(
+ 'HelperTestComment' => array(
+ 'fields' => array('BigField' => array('type' => 'integer'))
+ )
+ );
$this->Helper->setEntity('HelperTestComment', true);
$this->Helper->setEntity('HelperTestComment.BigField');
@@ -323,6 +326,25 @@ public function testSetEntityAssociatedCamelCaseField() {
}
/**
+ * Test that multiple fields work when they are camelcase and in fieldset
+ *
+ * @return void
+ */
+ public function testSetEntityAssociatedCamelCaseFieldHabtmMultiple() {
+ $this->Helper->fieldset = array(
+ 'HelperTestComment' => array(
+ 'fields' => array('Tag' => array('type' => 'multiple'))
+ )
+ );
+ $this->Helper->setEntity('HelperTestComment', true);
+ $this->Helper->setEntity('Tag');
+
+ $this->assertEquals('Tag', $this->Helper->model());
+ $this->assertEquals('Tag', $this->Helper->field());
+ $this->assertEquals(array('Tag', 'Tag'), $this->Helper->entity());
+ }
+
+/**
* test that 'view' doesn't break things.
*
* @return void
View
@@ -454,23 +454,26 @@ public function setEntity($entity, $setScope = false) {
$this->_association = null;
- // check for associated model.
- $reversed = array_reverse($parts);
- foreach ($reversed as $part) {
- if (empty($this->fieldset[$this->_modelScope]['fields'][$part]) && preg_match('/^[A-Z]/', $part)) {
- $this->_association = $part;
- break;
- }
- }
-
// habtm models are special
if (
isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
) {
+ $this->_association = $parts[0];
$entity = $parts[0] . '.' . $parts[0];
+ } else {
+ // check for associated model.
+ $reversed = array_reverse($parts);
+ foreach ($reversed as $part) {
+ if (
+ !isset($this->fieldset[$this->_modelScope]['fields'][$part]) &&
+ preg_match('/^[A-Z]/', $part)
+ ) {
+ $this->_association = $part;
+ break;
+ }
+ }
}
-
$this->_entityPath = $entity;
return;
}

0 comments on commit 1743eaa

Please sign in to comment.