Browse files

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

…t conditions. Fixes #266
  • Loading branch information...
1 parent 0960abc commit ec5d9729b0b1126226e1b7ab9c93c271b4828feb @markstory markstory committed Feb 27, 2010
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
View
3 cake/libs/model/model.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])) {
View
16 cake/tests/cases/libs/model/model_read.test.php
@@ -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() {
@@ -6378,6 +6379,21 @@ function testFindCount() {
}
/**
+ * 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)
*
* @return void

0 comments on commit ec5d972

Please sign in to comment.