V
V
Vitaly Melnikov2018-04-20 17:18:00
MySQL
Vitaly Melnikov, 2018-04-20 17:18:00

OneToOne (JOIN) vs extra field on entity?

The page displays a catalog of companies with their logos.
There are entities^ Company and File
Files are taken from the storage, the path is generated by the file storage method
I think about the decision to add the logo property to the Company:
Option 1: write the path to the file in the storage along with the name - path/to/logo.jpg
pluses: no extra request to the database to get the path and file name
minus: duplication of information in the database in the files table (there are already path and file fields)
Option 2; write only the file ID - 357
pros no duplication of information in the database
cons: an extra request to the database to get the path and name
Have I taken into account all the pros/cons?
Maybe there are other options?
What is the usual solution for such a problem?
Thank you all in advance for your replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2018-04-20
@Vmelnikoff

Duplicate data is only worth it if there is an urgent need. For example, high load on the database. Otherwise, normalize the base.

V
voronkovich, 2018-04-20
@voronkovich

There are no particular pros and cons here. This question is not about Doctrine. But the second option is definitely better. If you feel sorry for extra requests - use the cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question