Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix discrepancy in Model::field when Model::id is null
When using ClassRegistry::init for instance
  • Loading branch information
tersmitten committed Jun 8, 2017
1 parent 77b7ccf commit ddbdf17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -1653,7 +1653,7 @@ public function read($fields = null, $id = null) {
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-field
*/
public function field($name, $conditions = null, $order = null) {
if ($conditions === null && $this->id !== false) {
if ($conditions === null && !in_array($this->id, [false, null], true)) {
$conditions = array($this->alias . '.' . $this->primaryKey => $this->id);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -7041,6 +7041,12 @@ public function testFindField() {

$result = $TestModel->field('COUNT(*)', true);
$this->assertEquals(4, $result);

$TestModel->id = null;
$result = $TestModel->field('user', array(
'user' => 'mariano'
));
$this->assertEquals('mariano', $result);
}

/**
Expand Down

0 comments on commit ddbdf17

Please sign in to comment.