Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/system/Models/ReplaceModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.6.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
Loading