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

Auditing models with a Composite Primary Key - possible? #700

Open
robvitaro opened this issue Mar 5, 2024 · 1 comment
Open

Auditing models with a Composite Primary Key - possible? #700

robvitaro opened this issue Mar 5, 2024 · 1 comment

Comments

@robvitaro
Copy link

Can audited support the following scenario using Rails 7.1's composite primary keys?

class Foo
  has_many :foo_bars
  audited
  has_associated_audits
end

class Bar
  has_many :foo_bars
  audited
  has_associated_audits
end

class FooBar
  self.primary_key = [:foo_id, :bar_id] # i.e., there is no "id" column
  belongs_to :foo
  belongs_to :bar

  audited associated_with: :foo
  audited associated_with: :bar
end

Currently it would give an error similar to this:

ActiveRecord::CompositePrimaryKeyMismatchError:
        Association FoobBar#audits primary key ["foo_id", "bar_id"] doesn't match with foreign key auditable_id. Please specify query_constraints, or primary_key and foreign_key values.
@danielmorrison
Copy link
Member

Related to #585.

I think that'd be a great addition, but I don't personally have any projects with composite primary keys, so my motivation to add this is low. I'd gladly review a PR.

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