Skip to content

Bug: Tracking changes in Entity #9777

@neznaika0

Description

@neznaika0

PHP Version

8.4

CodeIgniter4 Version

latest, 4.6.3

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli-server (PHP built-in webserver)

Database

No response

What happened?

Since it became possible to set the properties of an entity after casting, there has been a problem tracking changes to the object. The principle of operation is now based on primitives: numbers, strings, and arrays...but not objects. By setting up casting in the Model, we get a single object for attributes and original. They are links. When you change a property, it also changes in the original. If we call hasChanged(), we will not get the correct result and the object will not save these changes to the database.
The situation is complicated by nested objects like $user->profile->username->name. They must also be monitored.

In Laravel, only values are saved (mostly json). However, I think it's possible to replace an object with a similar value, and this is considered an unchanged state. This is fine for the database, but it may cause an error in the PHP code.

Steps to Reproduce

Try working with objects instead of primitives. Call hasChanged(), compare $attributes and $original values after changing objects.

Expected Output

I would like to properly track the state of an object, along with its nesting.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions