I now have three tables, as follows
product表的字段为
product_id | product_name | type | price | category
type表的字段为
type_id | type_name
category表的字段为
category_id | category_name
Now this is the relationship
The type and category fields in product correspond to the type_id field of the type table and the category_id field of the category table respectively.
How to write the association in the model? In fact, the type and category fields are related to the other two tables in order to obtain to type_name and category_name.
I tried it all night. I don’t know whether it’s one-to-one or one-to-many. I’m so worried. Thanks to my friend for helping me.