Proper single-table inheritance support for Audit#revision #368
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Details
This PR fixes an issue where the subclass of a record from a single-inheritance table can't be recovered anymore with
Audit#revision
after the record was deleted.The reason for this is that the
inheritance_column
is not audited by default, which means the subclass is impossible to retrieve after a record has been deleted.My naive solution for this problem is to just track changes to the
inheritance_column
, and make sure the audited class is instantiated properly when a revision is created.Concerns
I am not fully aware why the
inheritance_column
has been ignored so far — this fix is based on the assumption that this was just an oversight. Are there any issues with this? All tests are passing on my machine though.If the inheritance column or the class name have ever been refactored without a migration of the existing audits’ inheritance column, an
ActiveRecord::SubclassNotFound
will be raised if an audit's revision is retrieved (because we rely on this). Should this be handled more gracefully, with a fall back to the parent class?