Skip to content

Commit

Permalink
Merge pull request #104 from Roxayl/bugfix/null-created-updated-fields
Browse files Browse the repository at this point in the history
Fix model with no updated_at or deleted_at columns
  • Loading branch information
nonoesp authored Mar 3, 2024
2 parents 9af7957 + 8ee3c20 commit 5b2786d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Mpociot/Versionable/VersionableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ private function purgeOldVersions()
*/
private function isValidForVersioning()
{
$dontVersionFields = isset( $this->dontVersionFields ) ? $this->dontVersionFields : [];
$removeableKeys = array_merge($dontVersionFields, [$this->getUpdatedAtColumn()]);
$removeableKeys = isset( $this->dontVersionFields ) ? $this->dontVersionFields : [];
if (($updatedAt = $this->getUpdatedAtColumn()) !== null) {
$removeableKeys[] = $updatedAt;
}

if (method_exists($this, 'getDeletedAtColumn')) {
$removeableKeys[] = $this->getDeletedAtColumn();
if (method_exists($this, 'getDeletedAtColumn') && ($deletedAt = $this->getDeletedAtColumn() !== null)) {
$removeableKeys[] = $deletedAt;
}

return ( count(array_diff_key($this->versionableDirtyData, array_flip($removeableKeys))) > 0 );
Expand Down

0 comments on commit 5b2786d

Please sign in to comment.