Skip to content
Open
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
2 changes: 1 addition & 1 deletion system/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function hasChanged(?string $key = null): bool
*/
public function injectRawData(array $data)
{
$this->attributes = $data;
$this->attributes = array_merge($this->attributes, $data);

$this->syncOriginal();

Expand Down
46 changes: 46 additions & 0 deletions tests/system/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,52 @@ public function testJsonSerializableEntity(): void
$this->assertSame(json_encode($entity->toArray()), json_encode($entity));
}

public function testInjectRawArray(): void
{
$entity = new class () extends Entity {
// The "user" property is not for DB
protected $attributes = [
'type' => 'Normal',
'limit' => 10,
'user' => 'John',
'_secure' => 'High',
];
protected $original = [
'type' => 'None',
'limit' => 0,
'user' => null,
'_secure' => 'Low',
];
};

$entity->injectRawData([
'type' => 'High',
'limit' => 15,
'_secure' => 'Normal',
'extra' => 'undefined',
]);

$this->assertSame(
[
'type' => 'High',
'limit' => 15,
'user' => 'John',
'_secure' => 'Normal',
'extra' => 'undefined',
],
$entity->toRawArray(),
);
$this->assertSame(
[
'type' => 'High',
'limit' => 15,
'user' => 'John',
'extra' => 'undefined',
],
$entity->toArray(),
);
}

private function getEntity(): object
{
return new class () extends Entity {
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Bugs Fixed
**********

- **Cookie:** The ``CookieInterface::SAMESITE_STRICT``, ``CookieInterface::SAMESITE_LAX``, and ``CookieInterface::SAMESITE_NONE`` constants are now written in ucfirst style to be consistent with usage in the rest of the framework.
- **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.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
Loading