Wednesday 27 November 2013

Database Table Names and and URL Structure

URLs

I regularly have to work with a host of different naming conventions.  For example, when dealing with an entity eg. Opportunity I will often find the table containing these entities named 'Opportunities' and a set of URL's for CRUD defined as

  • /opportunities
  • /opportunity/
  • /opportunity/create
  • /opportunity/delete/
  • /opportunity/update/
With URLs I find it much easier to work with plurals for consistency so I don't have to mess around mapping plural spellings to singular:


  • /opportunities
  • /opportunities/
  • /opportunities/create
  • /opportunities/delete/
  • /opportunities/update/
All the above URL's would map to a OpportunitiesController which would use a OpportunityService for interacting with the database.

Databases

On the flip side, I much prefer singular in the case of database tables.  My main reason for this is when working with Doctrine I don't have to add annotations to all my entity classes mapping the Opportunity entity to the opportunities table.  It also reads better when you have related tables eg. OpportunityMetadata table reads better than OpportunitiesMetadata.

This is just the way I do it, personal conventions are not important as long as they're consistent.