-
Notifications
You must be signed in to change notification settings - Fork 78
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 list all versions of a record? #212
Comments
Nope, there is no API for that. Do you have an idea how it could look like? And what is your use case? |
Something like I host a blog and need to list all revisions to a post with word-based diffs. |
That's an interesting question whether the current version should be included or not 🤔 And I'm thinking of having an enumerator instead of returning an Array right away (since created many records could affect performance). Something like this: post.versions #=> Enumerator
# you can use take to return all
post.versions.take
# or you take a few or call any Enumerable method
post.versions.take(2)
post.versions.find do
_1.title == "old title"
end
# we can also add options
post.versions(reverse: true) # from older to newer
post.versions(include_self: true) # return self as the first one (default) or the last one record (if reverse: true) And we should either use a less common name, say, class Post < ApplicationRecord
# add #versions method
has_logidze versions_accessor: true
# use a custom name
has_logidze versions_accessor: :log_versions
end WDYT? Am I missing something? |
That all sounds good to me. I vote calling it def arbitrary_versions_attr
logidze_versions
end and so no custom syntax is required. |
I'm new to this gem. Perusing the Readme, I couldn't find a method to retrieve all versions of a record.
I suppose I could just do:
But if there's a built-in way to do this, that would be even easier.
The text was updated successfully, but these errors were encountered: