mysql - Product, Category and Brand database relation in Rails -
I am creating a website using Rail and I am using MySQL for database. There are some products, there are categories like smartphones, tablets, digital watches, and then brands like Apple, Samsung and HTC. How can I make a relationship between Rail, I mean in a conceptual way.
There are many products in one category and one product can have many categories and then the brand is a brand of a product and there are many brand products.
Any help, whether conceptual or technical (in case of code), would be great.
Here's a structure that you can use:
Make Table 'Category' (`id`int (11) not tap,` range_name` is current (100) default null, primary key (`id`)) engine = inodebi; Table `brand` (` id` is not an integer (11) null, `brand_name` varchar (100) Default zero, primary key (` id`)) Engine = InnoDB; Table `product` (` id` integer (11) not null, `product_name` varchar (100) default zero,` product_specification` varchar (255) default zero, `id_brand` integer (11) default zero, primary key (` Id`), key `id_brand` (` id_brand`), constrain the `product_ibfk_1` foreign key (` id_brand`) reference `brand` (` id`)) engine = InnoDB; CREATE TABLE `protuct_category` (` id_product` integer (11) default zero, `id_category` integer (11) default zero, key 'id_product` (` id_product`), key` id_category` (`id_category`), constraint' protuct_category_ibfk_1` Enter the foreign key (`id_product`) References` product` (` id`), the barrier 'foreign key' (`id_category`) reference` category` (`id`)) engine = InnoDB protuct_category_ibfk_2`;
Comments
Post a Comment