Skip to content

Commit dce5359

Browse files
committed
fix: Fixed Entity::injectRawData()
1 parent 4806e65 commit dce5359

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

system/Entity/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function hasChanged(?string $key = null): bool
306306
*/
307307
public function injectRawData(array $data)
308308
{
309-
$this->attributes = $data;
309+
$this->attributes = array_merge($this->attributes, $data);
310310

311311
$this->syncOriginal();
312312

tests/system/Entity/EntityTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,52 @@ public function testJsonSerializableEntity(): void
10941094
$this->assertSame(json_encode($entity->toArray()), json_encode($entity));
10951095
}
10961096

1097+
public function testInjectRawArray(): void
1098+
{
1099+
$entity = new class () extends Entity {
1100+
// The "user" property is not for DB
1101+
protected $attributes = [
1102+
'type' => 'Normal',
1103+
'limit' => 10,
1104+
'user' => 'John',
1105+
'_secure' => 'High',
1106+
];
1107+
protected $original = [
1108+
'type' => 'None',
1109+
'limit' => 0,
1110+
'user' => null,
1111+
'_secure' => 'Low',
1112+
];
1113+
};
1114+
1115+
$entity->injectRawData([
1116+
'type' => 'High',
1117+
'limit' => 15,
1118+
'_secure' => 'Normal',
1119+
'extra' => 'undefined',
1120+
]);
1121+
1122+
$this->assertSame(
1123+
[
1124+
'type' => 'High',
1125+
'limit' => 15,
1126+
'user' => 'John',
1127+
'_secure' => 'Normal',
1128+
'extra' => 'undefined',
1129+
],
1130+
$entity->toRawArray(),
1131+
);
1132+
$this->assertSame(
1133+
[
1134+
'type' => 'High',
1135+
'limit' => 15,
1136+
'user' => 'John',
1137+
'extra' => 'undefined',
1138+
],
1139+
$entity->toArray(),
1140+
);
1141+
}
1142+
10971143
private function getEntity(): object
10981144
{
10991145
return new class () extends Entity {

user_guide_src/source/changelogs/v4.6.4.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Bugs Fixed
4141
- **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.
4242
- **Database:** Fixed a bug in ``BaseBuilder::compileOrderBy()`` where the method could overwrite ``QBOrderBy`` with a string instead of keeping it as an array, causing type errors and preventing additional ``ORDER BY`` clauses from being appended.
4343
- **Database:** Fixed a bug in ``SQLite3`` where the password parameter was ignored unless it was an empty string.
44+
- **Entity:** Fixed a bug in ``Entity::injectRawArray()`` where the default values of ``$attributes``values disappear. In the case when, after the DB query, the result did not contain all the values for the properties.
4445
- **Forge:** Fixed a bug in ``Postgre`` and ``SQLSRV`` where changing a column's default value using ``Forge::modifyColumn()`` method produced incorrect SQL syntax.
4546
- **Model:** Fixed a bug in ``Model::replace()`` where ``created_at`` field (when available) wasn't set correctly.
4647
- **Model:** Fixed a bug in ``Model::insertBatch()`` and ``Model::updateBatch()`` where casts were not applied to inserted or updated values.

0 commit comments

Comments
 (0)