Module: PaperTrailAssociationTracking::Reifiers::HasAndBelongsToMany Private

Defined in:
lib/paper_trail_association_tracking/reifiers/has_and_belongs_to_many.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Reify a single HABTM association of ‘model`.

Class Method Summary collapse

Class Method Details

.reify(pt_enabled, assoc, model, options, transaction_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/paper_trail_association_tracking/reifiers/has_and_belongs_to_many.rb', line 10

def reify(pt_enabled, assoc, model, options, transaction_id)
  version_ids = ::PaperTrail::VersionAssociation.
    where("foreign_key_name = ?", assoc.name).
    where("version_id = ?", transaction_id).
    pluck(:foreign_key_id)

  model.send(assoc.name).proxy_association.target =
    version_ids.map do |id|
      if pt_enabled
        version = load_version(assoc, id, transaction_id, options[:version_at])
        if version
          next version.reify(
            options.merge(
              has_many: false,
              has_one: false,
              belongs_to: false,
              has_and_belongs_to_many: false
            )
          )
        end
      end
      assoc.klass.where(assoc.klass.primary_key => id).first
    end
end