Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get what the collection looked like on a version? #255

Open
jalaj-hn opened this issue Feb 12, 2024 · 3 comments
Open

How to get what the collection looked like on a version? #255

jalaj-hn opened this issue Feb 12, 2024 · 3 comments

Comments

@jalaj-hn
Copy link

My collection's version is 22 for example and I want to know what it looked like at version 5. Is there a inbuilt way to do that?

@jalaj-hn jalaj-hn changed the title How to get what the collection looked like a version? How to get what the collection looked like on a version? Feb 12, 2024
@dblock
Copy link
Collaborator

dblock commented Feb 12, 2024

Tracks let you get the original and the modified version.

track = post.history_tracks.first
track.original # {}
track.modified # { "title" => "Test", "body" => "Post", "comments" => [{ "_id" => "575fa9e667d827e5ed00000d", "title" => "test", "body" => "comment" }], ... }

I think it'd be great to add a helper [] method to find one at a specific version, I'd like something like post.history_tracks[22], post.history_tracks.versions[22], or post.history_tracks.find(22) to work. Want to give it a shot?

@jalaj-hn
Copy link
Author

jalaj-hn commented Feb 13, 2024

Tracks let you get the original and the modified version.

Thanks. This will give me the original value of changed fields. So to get the whole collection with all its fields, I'll need to loop over the tracks and form the collection, right?

I like the helper method suggestion, I'll try to find some time on weekend and work on it.

@dblock
Copy link
Collaborator

dblock commented Feb 13, 2024

Thanks. This will give me the original value of changed fields. So to get the whole collection with all its fields, I'll need to loop over the tracks and form the collection, right?

Are you trying to find a state for multiple records? I think some helper methods for that, even if inefficient, could be awesome, e.g. Post.all.at(timestamp), etc.

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

No branches or pull requests

2 participants