many changes

This commit is contained in:
2012-12-03 18:39:36 +01:00
parent e3dc6a7c68
commit 7d64ab2022
37 changed files with 540 additions and 101 deletions
+17 -1
View File
@@ -5,10 +5,26 @@ class Product
property :code
property :price, type: Float
belongs_to :product_category
#belongs_to :product_category
has_and_belongs_to_many :product_categories, storing_keys: false
belongs_to :supplier # direct! category is an aid
has_many :product_orders
validates :supplier_id, presence: true
after_save :persist_product_category_ids
def product_category_ids=(ids)
@product_category_ids = ids.select(&:present?)
end
private
def persist_product_category_ids
return unless @product_category_ids.present?
database.load(@product_category_ids).each do |product_category|
product_category.product_ids ||= []
product_category.product_ids |= [id]
product_category.save
end
end
end