PaperTrail override column in object_changes before save

431 views Asked by At

Currently I am using PaperTrail for model versioning an I have a situation in which I invite a team member. The created records after the "create" event is fired up is:

<PaperTrail::Version:0x0000558aeeff2b38 
id: 327, 
item_type: "TeamMember", 
item_id: 12, 
event: "create", 
whodunnit: "1", 
object: nil, 
created_at: Wed, 21 Dec 2022 15:57:04 UTC +00:00, 
object_changes: {"user_id"=>[nil, 42]}>

As shown below TeamMember model has an association with user and when it is created I save the user_id. PaperTrail keeps track of user_id and saved the id of user but instead I am interested of user name. I cannot do a find with the id when I display the log because the user with that id may not exist anymore in the future and it will result in record not found. On the other hand I cannot use reify because this is a "create" event and reify results in nil. Please help me how can I save user_name instead of user id on object_changes.

0

There are 0 answers