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

Associated models two levels deep #676

Open
camerondrysdale opened this issue Jun 23, 2023 · 1 comment
Open

Associated models two levels deep #676

camerondrysdale opened this issue Jun 23, 2023 · 1 comment

Comments

@camerondrysdale
Copy link

camerondrysdale commented Jun 23, 2023

We have a model structure like this in our app:

class Product < ApplicationRecord
  has_one :menu
  
  audited
  has_associated_audits
end

class Menu < ApplicationRecord
  belongs_to :product
  has_many :menu_items
  
  audited associated_with: :product
  has_associated_audits
end

class MenuItem < ApplicationRecord
  belongs_to :menu
  
  audited associated_with: :menu
end

And we want to see audits information against our Product when either the Menu or MenuItem is updated. We can see the Menu changes being displayed in the audits, but the MenuItem updates aren't coming through so seems it doesn't see them as an association through the Menu associated_with.

Does the Audited gem only support one-level deep associations? Or do we need to link the MenuItem to the Product (even though it doesn't have a direct relation to it).

@camerondrysdale
Copy link
Author

It seems doing:

class MenuItem < ApplicationRecord
  belongs_to :menu
  
  audited associated_with: :product
end

Does indeed work... however we lose the structure of the audits then... is this the correct way to handle multiple level models in Audited?

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

1 participant