Closed dixpac closed 1 year ago
Logidze doesn't care about what do you want to store in this reserved meta field; it's up to the developer to decide. how to serialize a responsible object.
I like the idea of using GlobalID though. Maybe, we can automatically use it in case an object responding to #to_global_id
is passed. And when reading responsible data, we can check if the value looks like a GlobalID and restore it.
Logidze doesn't care about what do you want to store in this reserved meta field; it's up to the developer to decide. how to serialize a responsible object.
Ahh cool, didn't catch that, yeah then I could do following, and it works 👍
product = Product.new.tap do |p|
p.name = "Test"
end
Logidze.with_responsible(user.to_gid) do
product.save
end
Logidze.with_responsible(device.to_gid) do
product.update(name: "New name")
end
I like the idea of using GlobalID though. Maybe, we can automatically use it in case an object responding to #to_global_id is passed. And when reading responsible data, we can check if the value looks like a GlobalID and restore it.
Yup, that is exactly what I was thinking, then this style of method would be unnecessary
def whodunnit
id = log_data.responsible_id
User.find(id) if id.present?
end
Closing in favor of https://github.com/palkan/logidze/issues/233
What if responsible_id can be from a different models.
For example for my use case, specific record can be changed by
User
or aDevice
? Would it make a sense to store also stringified object type for responsible for example:Or maybe
gid
could also work