From ce8637b31001ae3be50e930b8bf186d9545575c9 Mon Sep 17 00:00:00 2001 From: Andrew Hodgkinson Date: Thu, 29 Aug 2024 08:56:51 +1200 Subject: [PATCH] Add README.md note about custom audit table names --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 7a076c2c..29036261 100644 --- a/README.md +++ b/README.md @@ -425,6 +425,18 @@ Audited.config do |config| end ``` +#### Changing the table name + +If you use a custom audit model _and_ define a different table name inside it, you must mark the `Audited::Audit` superclass as abstract. Otherwise you may get exceptions from attempts to access the missing `audits` table, since ActiveRecord still "sees" a valid, non-abstract model class in `Audited::Audit` and may attempt to access information about its inferred related table. + +Due to complexities of autoloading, this is most reliably achieved inside the subclass itself: +```ruby +class CustomAudit < Audited::Audit + self.table_name = 'audit_trails' + superclass.abstract_class = true +end +``` + ### Enum Storage In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value: