Welcome Guest, Not a member yet? Register   Sign In
Inaccuracy? Edit Entity attributes
#1

(This post was last modified: 07-29-2022, 12:47 PM by ozornick.)

It's probably planned that way, but it doesn't seem right.
When the entity is received by the model, a class is created and the setAttributes() method is called (Set raw data array without any mutations)
For simple types, everything is fine. But for a date (or another class) there is a difference.

When I edit an entity, my attributes apply mutators.
Let's say I want to change my date of birth.


PHP Code:
        //  protected $dates = [ 'created_at',  'updated_at',  'date_birth'];
        $user->syncOriginal(); 
        
        
// hasChanged() > boolean false
        // toRawArray() > date_birth => string (10) "2008-02-06"
        $user->firstName $dto->firstName ?? $user->firstName;
        $user->dateBirth $dto->dateBirth ?? $user->dateBirth->format('Y-m-d');
        // ... other fields edit
        
        
// hasChanged() > boolean true
        // toRawArray() > date_birth => CodeIgniter\I18n\Time (6) 2000-10-13 00:00:00+04:00 MSD
        // BUT I did not change the date of birth - the mutator was applied  


I think this is incorrect behavior and you need to use the fill () method in the model or some other option.
Summary: The _original attributes will not match the changed _attributes, even if the string value is the same
Reply


Messages In This Thread
Inaccuracy? Edit Entity attributes - by ozornick - 07-29-2022, 12:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB