Search code examples
phplistcakephprelational-databasedatabase-normalization

CakePHP Normalization


I am debating over the amount of normalization to use in my tables.

For example, if I have a database table called players with columns such as name, hometown, etc...

Other columns are options bats (right, left, or switch), or status (active, injured) that with be displayed as radio buttons or drop downs.

Currently, our database stores these options in their own tables bats and statuses and we reference the related table with the fields bat_idand status_id.

If the bats and statuses tables are simply storing a list of names and ids and will always have less than 10 values, should I flatten the database and simply store the values directly in the players table?

When creating radio inputs for those fields I might have to execute a group by query on a large table. Would it make sense to store the possible values globally as an array in app/config/bootstrap.php or by using the configure class?


Solution

  • For my opinion you can really seldom overuse normalization. I'd avoid globals as much as I can.

    If your bats and statuses tables will hold "only" configuration or status key data you might put all of them together in a single table, accessible by namespace.

    E.g.:

      id | namespace | value
    ---------------------------
       1 | bats      | left
       2 | bats      | right
       3 | bats      | swing
       4 | status    | active
       5 | status    | injured
    

    ... etc, you get it. Simply have an index on the namespace to help the database - unless there are really only a few lines in there where a decent DB would ignore the index anyway.