-
Notifications
You must be signed in to change notification settings - Fork 653
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
different audit table per model? #471
Comments
I too am interested in this question! Code as it is now looks like this isn't supported, but I'd love to see the option in future. |
@Marri I think I found a quick and easy solution: in the initializer I've defined a custom model:
the Audit model is:
then in the model for which I want to audit to a different table:
|
@francescob This way is work for me ! Thanks But I have a little trouble. if executed this callback So I have to add:
But Have you ever had this situations? |
I provided a clean up method in the Audit class after_save :clean_up def clean_up do you see any problems with this? thanks! |
I wish that could be configurable too. |
The workarounds above don't seem thread-safe since they are modifying a global |
This appears to be an easy fix from the code. Instead of calling e.g. Could instead of calling def audited(options = {})
define_method :audit_class do
options[:audit_class_name]&.safe_constantize || Audit.audit_class
end
...
has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: audit_class.name, inverse_of: :auditable Then when you define your model e.g. User class User < AR::Base
audited audit_class_name: 'UserAudit'
end Associated audits don't even need to use the same class. There may be some other issues to solve around the |
Are we accepting feature changes? if yes, I will be happy to raise a PR to address this issue. |
is it possibile to have audits saved to different tables, for example <model_name>_audits ?
I've managed to save to a different table using the initializer to define a custom audit model, but that apply to all my models. Any idea?
The text was updated successfully, but these errors were encountered: