updating part2, far from finished
This commit is contained in:
+15
-5
@@ -21,15 +21,25 @@ class Product
|
||||
|
||||
def product_category_ids=(ids)
|
||||
@product_category_ids = ids.select(&:present?)
|
||||
is_dirty
|
||||
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
|
||||
@product_category_ids ||= []
|
||||
existing_product_categories = product_categories
|
||||
|
||||
# do nothing if nothing has changed
|
||||
return if @product_category_ids == existing_product_categories.map(&:id)
|
||||
|
||||
# clear removed product categories
|
||||
existing_product_categories.reject{|pc| @product_category_ids.include?(pc.id) }.each{|pc| pc.remove_product(self) }
|
||||
|
||||
|
||||
# Add product to newly added product categories
|
||||
database.load(@product_category_ids - existing_product_categories.map(&:id)).each do |product_category|
|
||||
product_category.add_product(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ class Section
|
||||
end
|
||||
return saves.all?
|
||||
end
|
||||
|
||||
def arrange_tables_in_columns_of(n)
|
||||
return unless n.present?
|
||||
n = n.to_i
|
||||
|
||||
Reference in New Issue
Block a user