Skip to main content

AssociatedRecordHistory

Description​

CM Admin supports tracking changes to associated models by specifying them in paper_trail_associations. This is useful when you want to show a single history timeline that includes the parent record and its related models.

Usage​

Add CmAdmin::PaperTrailAssociations to your host app's ApplicationRecord:

class ApplicationRecord < ActiveRecord::Base
include CmAdmin::PaperTrailAssociations
primary_abstract_class
end

In the model that needs associated history, call paper_trail_associations with the associations to include:

has_paper_trail
paper_trail_associations :po_items, :po_parts, :po_pieces, :release_orders, :ro_pieces, :attachments

Note:

  • has_paper_trail must be added to the model as well.
  • In the example above, the parent model has has_many :po_items, PoItem has has_many :po_parts, and so on.

Example associations:

has_many :po_items, inverse_of: :production_order, dependent: :destroy
has_many :po_parts, through: :po_items
has_many :po_pieces, through: :po_parts
has_many :release_orders, dependent: :destroy
has_many :ro_pieces, through: :release_orders
has_many :attachments, as: :attachable, dependent: :destroy