Browse Source

Fix notice error when impossible conditions are created.

Fixes #3084
mark_story 13 years ago
parent
commit
cffc36e4e0
2 changed files with 25 additions and 1 deletions
  1. 1 1
      lib/Cake/Model/Model.php
  2. 24 0
      lib/Cake/Test/Case/Model/ModelReadTest.php

+ 1 - 1
lib/Cake/Model/Model.php

@@ -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];

+ 24 - 0
lib/Cake/Test/Case/Model/ModelReadTest.php

@@ -3737,6 +3737,30 @@ class ModelReadTest extends BaseModelTest {
 	}
 
 /**
+ * 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
  *
  * @return void