Answer the question
In order to leave comments, you need to log in
Why use multiple models?
Hello. For example, there is a database with four tables: products, categories, orders, users. I watched different tutorials. Some make one model for all tables, others make their own model for each. What is the best way to do it and why?
Answer the question
In order to leave comments, you need to log in
For the sake of interest, give a link to a lesson where one model for everything. And so you were rightly told above one entity - one model. Write a way to combine categories and orders. Categories separately, and in the orders of the foreign key on the category, this is the meaning of relational databases. For example, separate entity models for categories, users, products, products have a foreign key for a category, and an order model has two foreign keys for a product and a user, and additional fields, for example, quantity and order date. With such a data model, you can manipulate the data as you like, the number of orders in a category, the number of orders a user has, the number of orders for a particular product, and so on and so forth.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question