Skip to content
This repository has been archived by the owner on Aug 10, 2019. It is now read-only.

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

Open
danielpuglisi opened this issue Nov 27, 2013 · 3 comments
Open

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

danielpuglisi opened this issue Nov 27, 2013 · 3 comments

Comments

@danielpuglisi
Copy link

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?

@mguymon
Copy link
Collaborator

mguymon commented Nov 27, 2013

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

@danielpuglisi
Copy link
Author

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"

@mguymon
Copy link
Collaborator

mguymon commented Nov 27, 2013

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants