Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix entity names for associated model date fields.

Fixes #1993
  • Loading branch information...
commit 85b86cb282d2a95964f127864068dbfc67b271b5 1 parent 09e7f1d
Mark Story markstory authored
Showing 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 lib/Cake/Test/Case/View/HelperTest.php
View
@@ -285,6 +285,10 @@ public function testSetEntityScoped() {
$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');
19 lib/Cake/View/Helper.php
View
@@ -433,21 +433,20 @@ public function setEntity($entity, $setScope = false) {
// 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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.