Skip to content

Commit

Permalink
Fix notice error when impossible conditions are created.
Browse files Browse the repository at this point in the history
Fixes #3084
  • Loading branch information
markstory committed Aug 2, 2012
1 parent 2728c62 commit cffc36e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -2863,7 +2863,7 @@ protected function _findNeighbors($state, $query, $results = array()) {
$query['order'] = $field . ' ASC';
$neighbors = $this->find('all', $query);
if (!array_key_exists('prev', $return)) {
$return['prev'] = $neighbors[0];
$return['prev'] = isset($neighbors[0]) ? $neighbors[0] : null;
}
if (count($neighbors) === 2) {
$return['next'] = $neighbors[1];
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -3736,6 +3736,30 @@ public function testFindNeighbors() {
$this->assertEquals($expected, $result);
}

/**
* Test find(neighbors) with missing fields so no neighbors are found.
*
* @return
*/
public function testFindNeighborsNoPrev() {
$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment');
$Article = new Article();

$result = $Article->find('neighbors', array(
'field' => 'Article.title',
'value' => 'Second Article',
'fields' => array('id'),
'conditions' => array(
'Article.title LIKE' => '%Article%'
),
'recursive' => 0,
));
$expected = array(
'prev' => null,
'next' => null
);
$this->assertEquals($expected, $result);
}
/**
* testFindCombinedRelations method
*
Expand Down

0 comments on commit cffc36e

Please sign in to comment.