end of day commit
This commit is contained in:
+27
-5
@@ -2,9 +2,31 @@ class Supplier
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :name
|
||||
has_many :lists
|
||||
has_many :orders, through: :lists
|
||||
has_many :products
|
||||
has_many :product_categories
|
||||
has_many :tables
|
||||
#has_many :orders, through: :lists
|
||||
has_many :products, dependent: :destroy
|
||||
has_many :product_categories, dependent: :destroy
|
||||
has_many :tables, dependent: :destroy
|
||||
#has_many :lists, through: :tables
|
||||
has_many :orders
|
||||
|
||||
def active_orders
|
||||
return @active_orders if @active_orders
|
||||
@active_orders = Order.active_for_supplier(id)
|
||||
@active_orders.include_relation(list: :table, product_orders: :order)
|
||||
@active_orders
|
||||
end
|
||||
|
||||
def active_lists
|
||||
return @active_lists if @active_lists
|
||||
@tables ||= active_tables
|
||||
@tables.include_relation(:lists)
|
||||
@active_lists = @tables.map(&:lists).flatten.select(&:active?)
|
||||
@active_lists.include_relations(:table, orders: {product_orders: :product})
|
||||
end
|
||||
|
||||
|
||||
def active_tables
|
||||
tables
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user