eloquent-versioning
eloquent-versioning copied to clipboard
Fix update method.
I noticed my update method wasn't working either. It was updating the main table, but erroring out on the versioned table. Using a duplicate key of 1 for every update no matter how many versions. Looks like getVersionColumn()
needed to be changed to getLatestVersionColumn()
.
I also added code that fetches the old version row and merges in the new updates. The way the old code was wrote it would only insert a versioned row with just the updated values, and null
out the existing data. I believe this was the desired behavior.
All data for updating is present in the Eloquent model. Why do you need an additional database call?
It has access to the data in the main table, but it does not contain the data for the version table. $affectedRecords = $this->getAffectedRecords();
only returns columns in the main table. That is why I added the additional query.