Skip to content

Revert applies casted data to raw attributes array #91

@simonhamp

Description

@simonhamp

Similar to #84, but basically I found that using setRawAttributes() is just not desired at all. When a model that has been reverted needs to be serialized (e.g. in an API response) it fails because the raw attributes array may contain data in a format that Eloquent doesn't expect.

You need some mechanism to convert the cast data back into its raw type if you're going to use setRawAttributes().

So I found it's better to simply attempt to set the values on the model directly e.g.:

foreach ($this->contents as $key => $value) {
    $this->versionable->$key = $value;
}

I noticed you were using forceFill at one point, which feels like it's the right approach, but I'm not clear why this needed to change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions