mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
parent
2728c6253e
commit
cffc36e4e0
2 changed files with 25 additions and 1 deletions
|
@ -2863,7 +2863,7 @@ class Model extends Object implements CakeEventListener {
|
|||
$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];
|
||||
|
|
|
@ -3736,6 +3736,30 @@ class ModelReadTest extends BaseModelTest {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue