diff --git a/system/BaseModel.php b/system/BaseModel.php index 4f1cf3dca18f..179964379937 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -1220,7 +1220,9 @@ public function replace(?array $row = null, bool $returnSQL = false) return false; } - $row = $this->setUpdatedField((array) $row, $this->setDate()); + $row = (array) $row; + $row = $this->setCreatedField($row, $this->setDate()); + $row = $this->setUpdatedField($row, $this->setDate()); return $this->doReplace($row, $returnSQL); } diff --git a/tests/system/Models/ReplaceModelTest.php b/tests/system/Models/ReplaceModelTest.php index a0a98ab696cd..776fcf7647fb 100644 --- a/tests/system/Models/ReplaceModelTest.php +++ b/tests/system/Models/ReplaceModelTest.php @@ -38,11 +38,13 @@ public function testReplaceRespectsUseTimestamps(): void $data['country'] = 'UK'; $sql = $this->model->replace($data, true); + $this->assertStringNotContainsString('created_at', (string) $sql); $this->assertStringNotContainsString('updated_at', (string) $sql); $this->model = $this->createModel(UserModel::class); $this->setPrivateProperty($this->model, 'useTimestamps', true); $sql = $this->model->replace($data, true); + $this->assertStringContainsString('created_at', (string) $sql); $this->assertStringContainsString('updated_at', (string) $sql); } } diff --git a/user_guide_src/source/changelogs/v4.6.4.rst b/user_guide_src/source/changelogs/v4.6.4.rst index c5e259894c43..121cafb9c814 100644 --- a/user_guide_src/source/changelogs/v4.6.4.rst +++ b/user_guide_src/source/changelogs/v4.6.4.rst @@ -33,6 +33,7 @@ Bugs Fixed - **Database:** Fixed a bug in ``Database::connect()`` which was causing to store non-shared connection instances in shared cache. - **Database:** Fixed a bug in ``Connection::getFieldData()`` for ``SQLSRV`` and ``OCI8`` where extra characters were returned in column default values (specific to those handlers), instead of following the convention used by other drivers. - **Forge:** Fixed a bug in ``Postgre`` and ``SQLSRV`` where changing a column's default value using ``Forge::modifyColumn()`` method produced incorrect SQL syntax. +- **Model:** Fixed a bug in ``Model::replace()`` where ``created_at`` field (when available) wasn't set correctly. See the repo's `CHANGELOG.md `_