audited
audited copied to clipboard
acts_as_tenant support?
My app uses multi tenancy with https://github.com/ErwinM/acts_as_tenant. Each model in the tenant has an account_id
column and the current tenant id is automatically added on commit.
I tried adding an account_id
column and then a model:
class Audit < ApplicationRecord
acts_as_tenant :account
end
I hoped that the account_id
would magically get added but not. Is there another method to set this before commit other than the :after_audit
callback? Looking to avoid a second transaction on every call here. I can access the id from current_account.id
. It's also saved in the audited record.
I am trying this for now:
def after_audit
self.audits.last.update!(account_id: self.account_id || nil)
end
Probably a few approaches, but one is to use a custom audit class: https://github.com/collectiveidea/audited#custom-audit-model
# config/initializers/audited.rb
Audited.config do |config|
config.audit_class = CustomAudit
end
class CustomAudit < Audited::Audit
acts_as_tenant :account
end