lundi 13 novembre 2023

Overriding object_changes on paper trails to store name corresponding to change in IDs

For associations, I am assigning IDs from different model to my model and therefore IDs are being changed. Papertrail tracks those changes, and this is the state of my object_changes:

{
  "updated_at": [
    "2023-11-13T08:54:26.346Z",
    "2023-11-13T08:56:06.961Z"
  ],
  "paying_id": [
    "ID1",
    "ID1 new"
  ],
  "company_ids": [
    [
      "ID1",
      "ID2",
      "ID3",
      "ID4"
    ],
    [
      "ID1 new",
      "ID2 new",
      "ID3 new"
    ]
  ]
}

However, in my view for the audit logs, I do not want to display the IDs, but display the names corresponding to those IDs. Right now, I am using if loops to query the names and send to the view. But there must be a better way than this. The docs is also against overriding object_changes, but if object_changes is not overriden, then how?

What is the correct way to do this?

Aucun commentaire:

Enregistrer un commentaire