mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Enumerable#uniq is fine (eg calling #uniq on an Array object), but now using #uniq on an ActiveRecord::Relation is deprecated in favour of #distinct (which modifies the query itself, as opposed to iterating over the results of the query).
14 lines
597 B
Ruby
14 lines
597 B
Ruby
class Schedule < ActiveRecord::Base
|
|
has_paper_trail meta: { custom_data: proc { |schedule| schedule.order_cycle_ids.to_s } }
|
|
|
|
has_many :order_cycle_schedules, dependent: :destroy
|
|
has_many :order_cycles, through: :order_cycle_schedules
|
|
has_many :coordinators, -> { distinct }, through: :order_cycles
|
|
|
|
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
|