Support alternative paper_trail versions association name#3354
Conversation
| 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.
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.
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.
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
versionshash in thehas_paper_trailcall. 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: