简体   繁体   中英

Database design using Symfony2 and Doctrine for lookup tables

I have an entity that contains several choice fields and to normalize the database, the best way is to have these fields linked to a lookup table. The lookup tables are two columns with the first as the primary key as an integery type and the second is the lookup value, usually a string of several words.

To display an entity object, I need to query each lookup table to get the values. Is this the standard wy of doing it or does anyone else have another method? Should there be only one lookup table or would I need a different lookup for each field? I think I need one for each field since I have to allow a user to choose the field that applies to them and only want to show the appropiate choices for each field.

Everything is stored in doctrine and the database, correct? No arrays or simple lookup objects stored only in Symfony/php?

I am using this as a reference for my naming and creating queries doctrine join multiple tables

In the end, I decided to add a lookup table to my database and add another entity to my Symfony project. The form to display the choice selection uses the entity type, and when I need to display the underlying selection in twig, I added a data transformer according to the docs from Symfony http://symfony.com/doc/current/cookbook/form/data_transformers.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM