Hey. I ask the question because I seem to lack a basic understanding of how everything works.
Situation: I am developing the first project using the MVC framework and MySQL database.
What is the data: Companies and News .
Each Company will have several photos. Therefore I make 3 tables in the database:
Photos table I make the fields:
- foreign_id (for one-to-many communication with
- filename (for file name)
Accordingly, from the code side, I have 3 models and 3 controllers. Responsible for working with photos PhotosController
Problem: now I want the News to have photos (of course, not the same as Companies :)). And here I come to the fact that I do not understand.
Question: what should I do in this situation - add an additional table for news pictures, similar to the
Photos table and let's say it is
Media . And link it to the news in the same way as
Photos are related to Companies ?
Or expand the
Photos table by entering the additional 'type' field there and designate to it who owns a specific entry - Company or News .
What are my doubts: if I make an additional table, I will have to do a separate controller which will duplicate the code of the PhotosController controller
If you make an additional field in the
Photos table, then there will also be complications of requests for data sampling and anything like that, not ok.
What do they do in such situations so that the code is DRY and the base is Feng Shui? Please tell me more! Thank.