phpcakephpinflector

CakePHP naming conventions in table names


For a CakePHP app I'm thinking about database table names that follow the CakePHP naming conventions. However many times I come across a general table that contains information that is not an entity on it's own but contains additional entity information. The information in this table is intended for re use so this is placed apart from the main entity table.

For example: I work with products that can sometimes be master products. In that case the table "products" link to the table "master_product_information" for extra information that I don't want in my "products" table.

Another example: A table that contains meta data of multiple pages. Normally I would name the table "pages_metadata", but for Cake this needs to be plural and "pages_metadatas" doesn't seem right. So once again I would go for "pages_metadata_information".

How do you name tables that do not contain entities? Is [entity]_information a good one?

I hope to hear some recommendations.

Thanks.


Solution

  • The right answer (IMO) is to just go with CakePHP conventions - life will be easiest that way, even if you have the occasional awkward table name.

    In your case, I'd name the "master_product_information" table master_products. The fact that it contains "information" about a master_product doesn't need to be specified in the table name. Just like a table that stores info about customers is a "customers" table, not a "customer_information" table.

    For "pages_metadata_information", I'm pretty sure 'metadata' is a plural term. I'd go with a name like page_metadata, or even just metadata. The fact that metadata is associated with a page, or pages, most likely doesn't need to be specified in the table name. Just like how a "teachers" table wouldn't be called "students_teachers", even though a teacher is always associated with students.

    Your table names might sometimes be a little awkward, but that's less hassle than breaking conventions, and you'll get used to it pretty quickly.