auditable icon indicating copy to clipboard operation
auditable copied to clipboard

How to load an object how it looked at a previous version

Open danielpuglisi opened this issue 11 years ago • 3 comments

Is there an easy way to load an object how it looked at a current state in its lifecycle?

E.g. I'm at version 110 and want to look how the object looked at version 80 including nested objects?

danielpuglisi avatar Nov 27 '13 10:11 danielpuglisi

So the docs need updating, but if you have the version option set to true

audit :title, :version => true

You can simply use AREL to find by version:

model.audits.where(:version => 80).first

mguymon avatar Nov 27 '13 15:11 mguymon

Yes, but that gives me an Auditable::Audit object.

I'm more looking for a way to update the attributes of an object directly with the modifications of an audit object but as far as I've seen there isn't something implemented in auditable yet?

E.g. to retrieve version 80 of a specific object someone would call something like audited_version(80) on a specific object:

model.audited_version(80)
# => Model id: 1, attribute_1: "string", attribute_2: "string"

danielpuglisi avatar Nov 27 '13 15:11 danielpuglisi

So you want to replay all the audits up to a version? It could work by merging all the audits together to make a hash of attributes and that could be applied to the model to return to that version's state.

mguymon avatar Nov 27 '13 16:11 mguymon