Delete Fix for parent child process in Menu

This commit is contained in:
PhyoTheingi
2017-06-05 18:31:56 +06:30
parent 9bb7eb7f17
commit 7b457400b2
15 changed files with 110 additions and 67 deletions

View File

@@ -8,5 +8,29 @@ class MenuCategory < ApplicationRecord
default_scope { order('order_by asc') }
def self.destroyCategory(menu_category)
# find the sub menu item of current item
sub_menu_cat = MenuCategory.where("menu_category_id=?",menu_category.id)
if sub_menu_cat.length != 0
sub_menu_cat.each do |sub|
if destroyCategory(sub)
end
end
# find the items of current menu item
items = MenuItem.where("menu_category_id=?",menu_category.id)
items.each do |item|
abc = MenuItem.deleteRecursive(item)
end
menu_category.destroy
return true
else
items = MenuItem.where("menu_category_id=?",menu_category.id)
items.each do |item|
abc = MenuItem.deleteRecursive(item)
end
menu_category.destroy
return false
end
end
end