Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: make version data serialization customizable #44

Open
hagabaka opened this issue Nov 8, 2018 · 0 comments
Open

Request: make version data serialization customizable #44

hagabaka opened this issue Nov 8, 2018 · 0 comments

Comments

@hagabaka
Copy link
Contributor

hagabaka commented Nov 8, 2018

Currently the serialization is done in VersionableTrait::versionablePostSave() with

$version->model_data = serialize($this->getAttributes());

and deserialization is done in Version::getModel() with

$model->fill(unserialize($modelData));

It would be nice if the method of serialization can be customized by overriding methods, for example to use JSONB column, or even a versions table with all the columns of the versioned model.

trait VersionableTrait
{
    protected function copyAttributesToVersion(Version $version)
    {
       $version->model_data       = serialize($this->getAttributes()); // default implementation
       // or
       $version->model_data = $this->getAttributesData(); // with a JSONB model_data column
       // or
       $version->fill($this->getAttributes()); // versions table with columns for all versioned attributes
    }
}

class Version
{
    protected function copyAttributesToVersionable($model)
    {
         $model->fill(unserialize($modelData));  // default implementation
         $model->fill($modelData); // with a JSONB model_data column
         $model->fill(array_only($this->getAttributes(), $versionedAttributes)); // versions table with columns for all versioned attributes
    }
}
hagabaka pushed a commit to hagabaka/versionable that referenced this issue Nov 16, 2018
This allows extending the Version class and changing the migration
to store model data differently

Implements mpociot#44
hagabaka pushed a commit to hagabaka/versionable that referenced this issue Nov 16, 2018
This allows extending the Version class and changing the migration
to store model data differently

Implements mpociot#44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant