feat: Category API to handle linked categories and parent-sub categories (#4879)
This commit is contained in:
5
db/migrate/20220623113405_add_parent_id_to_category.rb
Normal file
5
db/migrate/20220623113405_add_parent_id_to_category.rb
Normal 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
|
||||
12
db/migrate/20220623113604_create_related_categories.rb
Normal file
12
db/migrate/20220623113604_create_related_categories.rb
Normal 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
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddLinkedCategoryIdToCategories < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_reference :categories, :linked_category, foreign_key: { to_table: :categories }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user