feat: Category API to handle linked categories and parent-sub categories (#4879)

This commit is contained in:
Tejaswini Chile
2022-06-28 11:23:20 +05:30
committed by GitHub
parent c0249a1b5b
commit df1bf112ea
15 changed files with 286 additions and 29 deletions

View File

@@ -0,0 +1,5 @@
class AddParentIdToCategory < ActiveRecord::Migration[6.1]
def change
add_reference :categories, :parent_category, foreign_key: { to_table: :categories }
end
end

View File

@@ -0,0 +1,12 @@
class CreateRelatedCategories < ActiveRecord::Migration[6.1]
def change
create_table :related_categories do |t|
t.bigint :category_id
t.bigint :related_category_id
t.timestamps
end
add_index :related_categories, [:category_id, :related_category_id], unique: true
add_index :related_categories, [:related_category_id, :category_id], unique: true
end
end

View File

@@ -0,0 +1,5 @@
class AddLinkedCategoryIdToCategories < ActiveRecord::Migration[6.1]
def change
add_reference :categories, :linked_category, foreign_key: { to_table: :categories }
end
end