Skip to content

Commit

Permalink
Fix entity names for associated model date fields.
Browse files Browse the repository at this point in the history
Fixes #1993
  • Loading branch information
markstory committed Sep 17, 2011
1 parent 09e7f1d commit 85b86cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lib/Cake/Test/Case/View/HelperTest.php
Expand Up @@ -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');
Expand Down
19 changes: 9 additions & 10 deletions lib/Cake/View/Helper.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 85b86cb

Please sign in to comment.