Welcome Guest, Not a member yet? Register   Sign In
Naming database columns and form inputs
#1

Examples in the CI4 documentation use snake_case for database column names. Indeed the default values 'created_at', 'updated_at' and 'deleted_at' support this convention. 

CI4 entities promote using the same names for html form inputs as database column names. Doing so streamlines filling the database from html forms. So the convention to use snake_case in column names will (should) lead to the same convention for naming form inputs.


Doesn't this conflict with using camelCase for object properties? For example using both conventions I need to know where an entity property came from: if it was loaded from database I need to refer to it using snake case, but if was created by code at runtime I need to refer to it using camelCase. I need to keep track of which it is. 

Is snake_case for column names a widespread convention? 

Are there good reasons for it? I would love to hear what they are. 

I would appreciate any advice, even a good article to read. I haven't found one in my internet searching. 
Reply
#2

For PHP SEE:

PHP Standards Recommendations

Basic Coding Standard

Extended Coding Style Guide

For MySQL Database SEE:

MySQL naming - coding conventions: tips on mySQL database
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Thanks. 
following these conventions leads to a conflict with CI4 entities. 
Say I have a database with a field name called "some_category
Say I then instantiate an entity representing a row from this table and call it $myEntity. 
To refer to some_category I will need to call:
Code:
$myEntity->some_category


This contravenes the standard I see (but haven't found written down) that property names must  be in camelCase.

Are we ok with this conflict?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB