Skip to content
Permalink
Browse files

Model::find(first) no longer uses the id set in a model as the defaul…

…t conditions. Fixes #266
  • Loading branch information...
markstory committed Feb 27, 2010
1 parent 0960abc commit ec5d9729b0b1126226e1b7ab9c93c271b4828feb
Showing with 16 additions and 3 deletions.
  1. +0 −3 cake/libs/model/model.php
  2. +16 −0 cake/tests/cases/libs/model/model_read.test.php
@@ -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])) {
@@ -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() {
@@ -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)
*

0 comments on commit ec5d972

Please sign in to comment.
You can’t perform that action at this time.