GithubHelp home page GithubHelp logo

Comments (2)

camerondrysdale avatar camerondrysdale commented on June 2, 2024

I've re-opened this as it does pose an interesting issue, so curious what the options are...

If you have a model setup like this:

class Collection < ApplicationRecord
  has_many :products

  audited
  has_associated_audits
end

class Product < ApplicationRecord
  belongs_to :collection

  audited associated_with: :product
end

class AnotherProduct < Product
  # some logic specific to AnotherProduct
end

When ever the Product or Collection is updated it will log the changes and these can be accessed from the Collection with:

@collection = Collection.first
@collection.own_and_associated_audits

However, if you were to do an update on the AnotherProduct model, you would see audits against that model:

@another_product = AnotherProduct.update(update_params)
@another_product.audits.present? => true

This makes sense, in that it was AnotherProduct that had the changes against it made... even though it inherits from the Product model. But it means you can't see those audits with:

@product = Product.where(name: 'AnotherProduct').first
@product.audits

Even though the record is the same, but the object in which the audit is associated is different, so it means you can't retrieve the audits, and also then means you can't see them against the collection itself.

Is there a way to get around this? Perhaps trick Audited into seeing the model name as something different? or perhaps being able to join inherited models somehow when pulling back the audit records?

from audited.

camerondrysdale avatar camerondrysdale commented on June 2, 2024

I was having a look at that method own_and_associated_audits:

def own_and_associated_audits
  Audited.audit_class.unscoped.where(auditable: self)
  .or(Audited.audit_class.unscoped.where(associated: self))
  .order(created_at: :desc)
end

Perhaps that can be monkey-patched to pull through associated inherited models too?

from audited.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.