-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support alternative paper_trail versions association name #3354
Support alternative paper_trail versions association name #3354
Conversation
@@ -116,7 +116,7 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p | |||
|
|||
current_page = page.presence || '1' | |||
|
|||
versions = object.nil? ? versions_for_model(model) : object.versions | |||
versions = object.nil? ? versions_for_model(model) : object.send(model.model.versions_association_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe .versions_association_name
is public
versions = object.nil? ? versions_for_model(model) : object.send(model.model.versions_association_name) | |
versions = object.nil? ? versions_for_model(model) : object.public_send(model.model.versions_association_name) |
Also is this covered by any existing tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote - this solves the same problem as #3269 with a slightly different approach (IIRC object.version_association_name
will execute a SQL query, while calling from the model does not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is public indeed, I've changed it to public_send (in 09449a6 to keep it squashed). I used send to keep it in line with the other send
usage in the file.
There was no test covering the versions usage, only one regarding the user used for the audit.
When using PaperTrail as an auditing gem, you can specify an alternative versions association by defining the `versions` hash in the `has_paper_trail` call. Initialization of PaperTrail (per model) stores the name of the association (since paper-trail-gem/paper_trail@3032b53, 23rd of July 2011) in `versions_association_name`. Using this method we can retrieve the history of a model when it uses a different name for the versions association. For example, using the following configuration won't break the auditing_adapter with this change: ```ruby has_paper_trail( version: :paper_trail_version, versions: { name: :paper_trail_versions, }, ) ```
cec972c
to
09449a6
Compare
@codealchemy would you consider either of proposed solutions? 🙂 |
I'm afraid anything beyond providing feedback here is out of my hands cc: @mshibuya |
Hi @mshibuya, any chance you might have some time to look at this (small) change? 😄 |
Thanks! |
When using PaperTrail as an auditing gem, you can specify an alternative versions association by defining the
versions
hash in thehas_paper_trail
call. Initialization of PaperTrail (per model) stores the name of the association (since paper-trail-gem/paper_trail@3032b53, 23rd of July 2011) inversions_association_name
. Using this method we can retrieve the history of a model when it uses a different name for the versions association.For example, using the following configuration won't break the auditing_adapter with this change: