mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix foreach error when useTable = false.
When calling model->create() with useTable = false, an error should not be triggered. Fixes #3480
This commit is contained in:
parent
d70730d722
commit
08cde9f5a2
2 changed files with 17 additions and 4 deletions
|
@ -1304,10 +1304,8 @@ class Model extends Object implements CakeEventListener {
|
||||||
if ($this->useTable !== false && (!is_array($this->_schema) || $field === true)) {
|
if ($this->useTable !== false && (!is_array($this->_schema) || $field === true)) {
|
||||||
$db = $this->getDataSource();
|
$db = $this->getDataSource();
|
||||||
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
|
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
|
||||||
if (method_exists($db, 'describe') && $this->useTable !== false) {
|
if (method_exists($db, 'describe')) {
|
||||||
$this->_schema = $db->describe($this);
|
$this->_schema = $db->describe($this);
|
||||||
} elseif ($this->useTable === false) {
|
|
||||||
$this->_schema = array();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_string($field)) {
|
if (is_string($field)) {
|
||||||
|
@ -1477,7 +1475,8 @@ class Model extends Object implements CakeEventListener {
|
||||||
$this->validationErrors = array();
|
$this->validationErrors = array();
|
||||||
|
|
||||||
if ($data !== null && $data !== false) {
|
if ($data !== null && $data !== false) {
|
||||||
foreach ($this->schema() as $field => $properties) {
|
$schema = (array)$this->schema();
|
||||||
|
foreach ($schema as $field => $properties) {
|
||||||
if ($this->primaryKey !== $field && isset($properties['default']) && $properties['default'] !== '') {
|
if ($this->primaryKey !== $field && isset($properties['default']) && $properties['default'] !== '') {
|
||||||
$defaults[$field] = $properties['default'];
|
$defaults[$field] = $properties['default'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -906,6 +906,20 @@ class ModelIntegrationTest extends BaseModelTest {
|
||||||
$this->assertEquals($Post->getColumnTypes(), array_combine($columns, $types));
|
$this->assertEquals($Post->getColumnTypes(), array_combine($columns, $types));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check schema() on a model with useTable = false;
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSchemaUseTableFalse() {
|
||||||
|
$model = new TheVoid();
|
||||||
|
$result = $model->schema();
|
||||||
|
$this->assertNull($result);
|
||||||
|
|
||||||
|
$result = $model->create();
|
||||||
|
$this->assertEmpty($result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* data provider for time tests.
|
* data provider for time tests.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue