Files
openfoodnetwork/app/models/schedule.rb
luisramos0 abd4f0b923 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
2020-02-07 10:06:58 +00:00

17 lines
609 B
Ruby

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
validates :order_cycles, presence: true
scope :with_coordinator, lambda { |enterprise| joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*') }
def current_or_next_order_cycle
order_cycles.where('orders_close_at > (?)', Time.zone.now).order('orders_close_at ASC').first
end
end