yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

DB Column and Table Naming #9815

Closed aliechti closed 8 years ago

aliechti commented 8 years ago

Would it not make sense, to use a more strict naming convention, in places where the DB is used?

I know that this was discussed more than once, but it felt wrong as I compared some properties of normal classes with properties of ActiveRecords.

In Yii2 a table is used in a class, which is named in the UpperCamelCase format. The columns are the properties in the object which should be named in the lowerCamelCaseFormat.

But if I look in the migration or the rbac module everything is snake_case. This leads to objects with snake_case properties which is not recomended in the code style sheet of Yii2.

I know too, that this is a very personal or company oriented decision, but if felt that it should be like my example below. In my opinion this should be in this way because of the object oriented way Yii2 handles SQL tables, rows and columns.

ClassName->propertyName
TableName.columnName
nineinchnick commented 8 years ago

Using such naming in most databases requires explicit quoting, as most databases are case insensitive by default. That's not convienient and adding any code that tries to convert naming automatically is too complex and confusing.

samdark commented 8 years ago

Also Yii doesn't provide full SQL abstraction so column names in queries would be still the ones that are actually in database.

aliechti commented 8 years ago

@samdark this is not what I wanted to archive. The case is that the actual column names do not match the expected naming convention. Column names should be the same as in the objects, nobody wants a conversion this would lead to confusion.

samdark commented 8 years ago

Well, that's up to the project about how to name DB columns. In some cases you don't even have a choice.

aliechti commented 8 years ago

but here with the migration and the rbac tables we have the choice...

samdark commented 8 years ago

We're sticking to what's common for SQL world: http://www.sqlstyle.guide