Files
openfoodnetwork/app/models/order_cycle.rb
2012-11-29 10:02:23 +11:00

28 lines
665 B
Ruby

class OrderCycle < ActiveRecord::Base
belongs_to :coordinator, :class_name => 'Enterprise'
belongs_to :coordinator_admin_fee, :class_name => 'EnterpriseFee'
belongs_to :coordinator_sales_fee, :class_name => 'EnterpriseFee'
has_many :exchanges, :dependent => :destroy
validates_presence_of :name, :coordinator_id
def suppliers
self.exchanges.where(:receiver_id => self.coordinator).map(&:sender).uniq
end
def distributors
self.exchanges.where(:sender_id => self.coordinator).map(&:receiver).uniq
end
def variants
self.exchanges.map(&:variants).flatten.uniq
end
def products
self.variants.map(&:product).uniq
end
end