Browse Source

Fix entity names for associated model date fields.

Fixes #1993
mark_story 14 years ago
parent
commit
85b86cb282
2 changed files with 13 additions and 10 deletions
  1. 4 0
      lib/Cake/Test/Case/View/HelperTest.php
  2. 9 10
      lib/Cake/View/Helper.php

+ 4 - 0
lib/Cake/Test/Case/View/HelperTest.php

@@ -285,6 +285,10 @@ class HelperTest extends CakeTestCase {
 		$expected = array('HelperTestComment', 'id', 'time');
 		$this->assertEquals($expected, $this->Helper->entity());
 
+		$this->Helper->setEntity('HelperTestComment.created.year');
+		$expected = array('HelperTestComment', 'created', 'year');
+		$this->assertEquals($expected, $this->Helper->entity());
+
 		$this->Helper->setEntity(null);
 		$this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist');
 		$expected = array('ModelThatDoesntExist', 'field_that_doesnt_exist');

+ 9 - 10
lib/Cake/View/Helper.php

@@ -433,21 +433,20 @@ class Helper extends Object {
 
 		// Either 'body' or 'date.month' type inputs.
 		if (
-			($count === 1 &&
-			$this->_modelScope &&
-			$setScope == false) ||
-			(in_array($lastPart, $this->_fieldSuffixes) &&
-			$this->_modelScope &&
-			$parts[0] !== $this->_modelScope)
+			($count === 1 && $this->_modelScope && $setScope == false) ||
+			(
+				$count === 2 &&
+				in_array($lastPart, $this->_fieldSuffixes) &&
+				$this->_modelScope &&
+				$parts[0] !== $this->_modelScope
+			)
 		) {
 			$entity = $this->_modelScope . '.' . $entity;
 		}
 
-		// 0.name style inputs.
+		// 0.name, 0.created.month style inputs.
 		if (
-			$count === 2 &&
-			is_numeric($parts[0]) &&
-			!is_numeric($parts[1])
+			$count >= 2 && is_numeric($parts[0]) && !is_numeric($parts[1]) && $this->_modelScope
 		) {
 			$entity = $this->_modelScope . '.' . $entity;
 		}