Skip to content

Commit

Permalink
Model::find(first) no longer uses the id set in a model as the defaul…
Browse files Browse the repository at this point in the history
…t conditions. Fixes #266
  • Loading branch information
markstory committed Feb 27, 2010
1 parent 0960abc commit ec5d972
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 0 additions & 3 deletions cake/libs/model/model.php
Expand Up @@ -2105,9 +2105,6 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
function _findFirst($state, $query, $results = array()) {
if ($state == 'before') {
$query['limit'] = 1;
if (empty($query['conditions']) && !empty($this->id)) {
$query['conditions'] = array($this->escapeField() => $this->id);
}
return $query;
} elseif ($state == 'after') {
if (empty($results[0])) {
Expand Down
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/model/model_read.test.php
Expand Up @@ -4857,6 +4857,7 @@ function testCallbackDisabling() {
* Tests that the database configuration assigned to the model can be changed using
* (before|after)Find callbacks
*
* @access public
* @return void
*/
function testCallbackSourceChange() {
Expand Down Expand Up @@ -6377,6 +6378,21 @@ function testFindCount() {
$this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']);
}

/**
* Test that find('first') does not use the id set to the object.
*
* @return void
*/
function testFindFirstNoIdUsed() {
$this->loadFixtures('Project');

$Project =& new Project();
$Project->id = 3;
$result = $Project->find('first');

$this->assertEqual($result['Project']['name'], 'Project 1', 'Wrong record retrieved');
}

/**
* test find with COUNT(DISTINCT field)
*
Expand Down

0 comments on commit ec5d972

Please sign in to comment.