Fix notice error when impossible conditions are created.

Fixes #3084
This commit is contained in:
mark_story 2012-08-01 23:05:48 -04:00
parent 2728c6253e
commit cffc36e4e0
2 changed files with 25 additions and 1 deletions

View file

@ -2863,7 +2863,7 @@ class Model extends Object implements CakeEventListener {
$query['order'] = $field . ' ASC'; $query['order'] = $field . ' ASC';
$neighbors = $this->find('all', $query); $neighbors = $this->find('all', $query);
if (!array_key_exists('prev', $return)) { if (!array_key_exists('prev', $return)) {
$return['prev'] = $neighbors[0]; $return['prev'] = isset($neighbors[0]) ? $neighbors[0] : null;
} }
if (count($neighbors) === 2) { if (count($neighbors) === 2) {
$return['next'] = $neighbors[1]; $return['next'] = $neighbors[1];

View file

@ -3736,6 +3736,30 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result); $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 * testFindCombinedRelations method
* *