VentureCraft / revisionable

Easily create a revision history for any laravel model
http://twitter.com/duellsy
MIT License
2.55k stars 348 forks source link

Invalid foreign key for SoftDelete returns unknown instead of the original id #428

Closed coamw2 closed 1 year ago

coamw2 commented 1 year ago

We need a way to get the id value for foreign keys where they have been soft deleted.

e.g job table with foreign key applicant_id

If I change the applicant_id then on the job history I get old_value = 1 and new_value = 2

If I soft delete the applicant with id = 1 then I get old_value = unknown and new_value = 2

I can see in the revisions table that old_value = 1 however, so I'm guessing some check is happening because it's a foreign key where it retrieves the applicant model and isTrashed is not used and therefore it fails to find and returns unknown, whereas I just need the history to give me the database value of 1 in this instance.

coamw2 commented 1 year ago

My mistake. Incase anyone in future gets this issue:

$history->oldValue() will return the foreign key value if valid e.g unknown or 1234 or Jeff

$history->old_value will return the exact value in database e.g 1234