Add custom_data column to paper_trail versions table so we can track a specific list of ids in a model

Activate paper_trail in order_cycles and schedules and track each others ids

An alternative way of doing this would be to use a gem for paper_trail associations but this way we avoid adding a new dependency to the app
This commit is contained in:
luisramos0
2019-12-02 17:43:21 +00:00
parent e1eface5f8
commit abd4f0b923
5 changed files with 15 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ class OrderCycle < ActiveRecord::Base
has_many :distributors, source: :receiver, through: :cached_outgoing_exchanges, uniq: true
has_and_belongs_to_many :schedules, join_table: 'order_cycle_schedules'
has_paper_trail meta: { custom_data: :schedule_ids }
attr_accessor :incoming_exchanges, :outgoing_exchanges

View File

@@ -1,5 +1,7 @@
class Schedule < ActiveRecord::Base
has_and_belongs_to_many :order_cycles, join_table: 'order_cycle_schedules'
has_paper_trail meta: { custom_data: :order_cycle_ids }
has_many :coordinators, uniq: true, through: :order_cycles
attr_accessible :name, :order_cycle_ids

View File

@@ -1 +1,7 @@
PaperTrail.config.track_associations = false
module PaperTrail
class Version < ActiveRecord::Base
attr_accessible :custom_data
end
end

View File

@@ -0,0 +1,5 @@
class AddCustomDataToVersions < ActiveRecord::Migration
def change
add_column :versions, :custom_data, :string
end
end

View File

@@ -1202,6 +1202,7 @@ ActiveRecord::Schema.define(:version => 20191023172424) do
t.string "whodunnit"
t.text "object"
t.datetime "created_at"
t.string "custom_data"
end
add_index "versions", ["item_type", "item_id"], :name => "index_versions_on_item_type_and_item_id"