mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #10742 from tersmitten/discrepancy-in-modelid-when-using-classregistryinit-versus
Fix discrepancy in Model::field when Model::id is null
This commit is contained in:
commit
e2d8f04f85
2 changed files with 7 additions and 1 deletions
|
@ -1653,7 +1653,7 @@ class Model extends CakeObject implements CakeEventListener {
|
||||||
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-field
|
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-field
|
||||||
*/
|
*/
|
||||||
public function field($name, $conditions = null, $order = null) {
|
public function field($name, $conditions = null, $order = null) {
|
||||||
if ($conditions === null && $this->id !== false) {
|
if ($conditions === null && !in_array($this->id, array(false, null), true)) {
|
||||||
$conditions = array($this->alias . '.' . $this->primaryKey => $this->id);
|
$conditions = array($this->alias . '.' . $this->primaryKey => $this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7041,6 +7041,12 @@ class ModelReadTest extends BaseModelTest {
|
||||||
|
|
||||||
$result = $TestModel->field('COUNT(*)', true);
|
$result = $TestModel->field('COUNT(*)', true);
|
||||||
$this->assertEquals(4, $result);
|
$this->assertEquals(4, $result);
|
||||||
|
|
||||||
|
$TestModel->id = null;
|
||||||
|
$result = $TestModel->field('user', array(
|
||||||
|
'user' => 'mariano'
|
||||||
|
));
|
||||||
|
$this->assertEquals('mariano', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue