eloquent-versioning icon indicating copy to clipboard operation
eloquent-versioning copied to clipboard

Fix update method.

Open chriscarpenter12 opened this issue 8 years ago • 2 comments

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.

chriscarpenter12 avatar Dec 23 '16 20:12 chriscarpenter12

All data for updating is present in the Eloquent model. Why do you need an additional database call?

markusjwetzel avatar Dec 23 '16 21:12 markusjwetzel

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.

chriscarpenter12 avatar Dec 23 '16 22:12 chriscarpenter12