Skip to content

Commit cffc36e

Browse files
committed
Fix notice error when impossible conditions are created.
Fixes #3084
1 parent 2728c62 commit cffc36e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Cake/Model/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ protected function _findNeighbors($state, $query, $results = array()) {
28632863
$query['order'] = $field . ' ASC';
28642864
$neighbors = $this->find('all', $query);
28652865
if (!array_key_exists('prev', $return)) {
2866-
$return['prev'] = $neighbors[0];
2866+
$return['prev'] = isset($neighbors[0]) ? $neighbors[0] : null;
28672867
}
28682868
if (count($neighbors) === 2) {
28692869
$return['next'] = $neighbors[1];

lib/Cake/Test/Case/Model/ModelReadTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,30 @@ public function testFindNeighbors() {
37363736
$this->assertEquals($expected, $result);
37373737
}
37383738

3739+
/**
3740+
* Test find(neighbors) with missing fields so no neighbors are found.
3741+
*
3742+
* @return
3743+
*/
3744+
public function testFindNeighborsNoPrev() {
3745+
$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment');
3746+
$Article = new Article();
3747+
3748+
$result = $Article->find('neighbors', array(
3749+
'field' => 'Article.title',
3750+
'value' => 'Second Article',
3751+
'fields' => array('id'),
3752+
'conditions' => array(
3753+
'Article.title LIKE' => '%Article%'
3754+
),
3755+
'recursive' => 0,
3756+
));
3757+
$expected = array(
3758+
'prev' => null,
3759+
'next' => null
3760+
);
3761+
$this->assertEquals($expected, $result);
3762+
}
37393763
/**
37403764
* testFindCombinedRelations method
37413765
*

0 commit comments

Comments
 (0)