• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database lookup tables and models

I have quite a few lookup tables in a database for a current project and really have two questions.

First, is it good practice to create a model for each lookup table even if the table would only be used to make a dropdown? Maybe that is overkill, but I'm not sure.

Second, I've read articles that talk about "keeping your data in the database" as opposed to a bunch of static lists for creating dropdown menus, but obviously for some lists (especially with only 5 or 6 options) it's hard to justify creating a table just for them. In my project I have lookup tables for states, counties, river basins, river sub-basins, etc. Is there a best practice when it comes deciding on when it is time to create a lookup table, vs a static list? Or should basically all data be in the database without any static lists or arrays hardcoded? I know this also may be personal preference.

I use a single model to look up both static lists and lists stored in the DB. That way, my app is oblivious of the source and I can still optimize for speed. Of course, there is DB caching as part of CI but this was simple enough.

I pass in the type of data I want back in a list, and I make sure that array is suitable for use in form_dropdown().

[eluser]Randy Casburn[/eluser]
@jleequeen - If the application is going to out live you, then consistency is important. I would recommend making all references to all data sources consistent. That way when someone replaces you (or you look back at this in three years long after you've forgotten why you did what you did), the consistency in your design will make learning or re-learning the design less painful. There may be a tiny performance hit here or there, but you will thank yourself ten times for doing things "consistently" down the road.

Just my 2c.



I have done what you suggested and created a model just for lists that populate drop down menus. I think that is the best solution in my case.


Your exactly right when it comes to consistency being of importance. I know this app will outlive me, so I definitely want to make it less of a pain for the poor soul that follows me, lol.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.