spatie / laravel-schemaless-attributes

Add schemaless attributes to Eloquent models
https://spatie.be/en/opensource
MIT License
1.01k stars 58 forks source link

Logged without changes with spatie/laravel-activitylog #61

Closed vaibhavpandeyvpz closed 4 years ago

vaibhavpandeyvpz commented 4 years ago

Hi there. I am trying to use this package in an app that uses spatie/laravel-activitylog. If I change any of the model attributes, the schemaless attribute gets logged into activity as well (flagged as changed). I am curious to knowing what could be causing this?

The model class is defined as follows:

class Something extends Model
{
    use LogsActivity;

    protected static $logFillable = true;
    protected static $logOnlyDirty = true;

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'enabled' => 'boolean',
        'settings' => 'array',
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'enabled', 'settings',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'settings',
    ];

    public function getSettingsAttribute(): SchemalessAttributes
    {
        return SchemalessAttributes::createForModel($this, 'settings');
    }

    public function scopeWithSettings(): Builder
    {
        return SchemalessAttributes::scopeWithSchemalessAttributes('settings');
    }
}

Upon updating enabled attribute value, settings attribute is also logged as changed. My best guess is because of getSettingsAttribute returning an object of SchemalessAttributes which is later compared with stored array type when checking for dirty. Any hints?

spatie-bot commented 4 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.