Class: RecordVersion

Inherits:
RecordVersionBase show all
Includes:
PaperTrail::VersionConcern
Defined in:
app/models/record_version.rb

Overview

== Schema Information

Table name: versions(partitioned,partition_key:created_at)
Database name: versions

id :integer not null, primary key
event :string(255) not null
ip :string(255)
item_type :string(255) not null
object_changes :jsonb
reference_data :jsonb
url :text
whodunnit :string(255)
created_at :datetime not null
item_id :integer not null

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_scopes(auth_object = nil) ⇒ Object



43
44
45
# File 'app/models/record_version.rb', line 43

def self.ransackable_scopes(auth_object = nil)
  %i[with_changes_to]
end

.with_attribute_changedActiveRecord::Relation<RecordVersion>

A relation of RecordVersions that are with attribute changed. Active Record Scope

Returns:

See Also:



32
# File 'app/models/record_version.rb', line 32

scope :with_attribute_changed, ->(attribute) { where('object_changes ?& array[:keys]', keys: [attribute]) }

Instance Method Details

#changesObject



39
40
41
# File 'app/models/record_version.rb', line 39

def changes
  (object_changes || {}).reject { |_k, v| v.all?(&:nil?) }
end

#itemItem

Returns:

See Also:



26
# File 'app/models/record_version.rb', line 26

belongs_to :item, polymorphic: true

#objectObject

Fake it!



35
36
37
# File 'app/models/record_version.rb', line 35

def object
  {}
end

#responsible_partyParty

Returns:

See Also:



25
# File 'app/models/record_version.rb', line 25

belongs_to :responsible_party, foreign_key: :whodunnit, class_name: 'Party', optional: true