Skip to content
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

audited on application-record level disturbs associated audits #663

Closed
chmich opened this issue Feb 23, 2023 · 3 comments
Closed

audited on application-record level disturbs associated audits #663

chmich opened this issue Feb 23, 2023 · 3 comments

Comments

@chmich
Copy link

chmich commented Feb 23, 2023

Hi,

regarding to associated audits i have this setup for a polymorphic association and it's working well:

class Memo < ApplicationRecord
  belongs_to :memo_writer, polymorphic: true, required: true
  audited associated_with: :memo_writer
end

class Employee < ApplicationRecord
  audited
  has_many :memos, as: :memo_writer
  has_associated_audits
end

Problem

Now i want to exclude all created_at and updated_at on application record level for the whole database:

class ApplicationRecord < ActiveRecord::Base
  audited except: [:created_at, :updated_at]
end

At the point there is placed any audited on the super class (ApplicationRecord) audited doesn't fillup the columns associated_id and associated_type on the audits table and associated audits are no more working.

Suggestion

it'd be fine if there'd be the option for setting defaults that can be overriden in the model.

@danielmorrison
Copy link
Member

Yes, audited isn't intended to be called multiple times that way.

However, those particular columns also aren't meant to be audited:

@ignored_attributes = %w[lock_version created_at updated_at created_on updated_on]

Are you seeing a situation where they are getting audited?

@danielmorrison
Copy link
Member

If you have other columns you want to exclude, you can use non_audited_columns = [:first_name, :last_name] in a model.

@chmich
Copy link
Author

chmich commented Mar 10, 2023

Thanks @danielmorrison good to know that and for me thats answered

@chmich chmich closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants