samedi 25 avril 2015

DB Table of constants vs constants in code


Eternal question.

I have a table moments_of_day:

id name
1  Morning
2  Afternoon
3  Evening
4  Night

And then an other table, meals, references it with moments_of_day_id.

And then, in my PHP code I want to get all meals of morning.

What's the best option? Should I repeat constants in my PHP MomentsOfDay model doing something like next code?

const MORNING = 1;

By repeating constants I think it can be dangerous. If in the future the table changes I also have to add it to the MomentsOfDay model.

What do you think?


Aucun commentaire:

Enregistrer un commentaire