Skip to content

Commit

Permalink
Removed overriding of recursive to 0 in Model::_findNeighbors() if 'r…
Browse files Browse the repository at this point in the history
…ecusive' option is not specified in find options. Closes #860
  • Loading branch information
ADmad committed Jan 29, 2011
1 parent 01801a7 commit 88d5db7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 4 additions & 5 deletions cake/libs/model/model.php
Expand Up @@ -331,9 +331,9 @@ class Model extends Object {
public $__backAssociation = array();

public $__backInnerAssociation = array();

public $__backOriginalAssociation = array();

public $__backContainableAssociation = array();

/**
Expand Down Expand Up @@ -1067,7 +1067,7 @@ public function hasField($name, $checkVirtual = false) {
}

/**
* Check that a method is callable on a model. This will check both the model's own methods, its
* Check that a method is callable on a model. This will check both the model's own methods, its
* inherited methods and methods that could be callable through behaviors.
*
* @param string $method The method to be called.
Expand Down Expand Up @@ -2156,7 +2156,7 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =

if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
$return = $this->Behaviors->trigger(
'beforeFind',
'beforeFind',
array(&$this, $query),
array('break' => true, 'breakOn' => array(false, null), 'modParams' => 1)
);
Expand Down Expand Up @@ -2321,7 +2321,6 @@ function _findList($state, $query, $results = array()) {
*/
protected function _findNeighbors($state, $query, $results = array()) {
if ($state == 'before') {
$query = array_merge(array('recursive' => 0), $query);
extract($query);
$conditions = (array)$conditions;
if (isset($field) && isset($value)) {
Expand Down
15 changes: 10 additions & 5 deletions cake/tests/cases/libs/model/model_read.test.php
Expand Up @@ -3504,11 +3504,14 @@ public function testFindNeighbors() {
$expected = array(
'prev' => null,
'next' => array(
'Article' => array('id' => 2)
'Article' => array('id' => 2),
'Comment' => array(),
'Tag' => array()
));
$this->assertEqual($result, $expected);

$TestModel->id = 2;
$TestModel->recursive = 0;
$result = $TestModel->find('neighbors', array(
'fields' => array('id')
));
Expand All @@ -3525,12 +3528,14 @@ public function testFindNeighbors() {
$this->assertEqual($result, $expected);

$TestModel->id = 3;
$TestModel->recursive = 1;
$result = $TestModel->find('neighbors', array('fields' => array('id')));
$expected = array(
'prev' => array(
'Article' => array(
'id' => 2
)),
'Article' => array('id' => 2),
'Comment' => array(),
'Tag' => array()
),
'next' => null
);
$this->assertEqual($result, $expected);
Expand Down Expand Up @@ -4793,7 +4798,7 @@ function bindWithCustomPrimaryKey() {
}

/**
* test that calling unbindModel() with reset == true multiple times
* test that calling unbindModel() with reset == true multiple times
* leaves associations in the correct state.
*
* @return void
Expand Down

0 comments on commit 88d5db7

Please sign in to comment.