Reputation: 505
What is the right plural/singular table naming convention in CakePHP.
This:
posts
posts_pictures
posts_picture_captions <-- Not sure about this
Or this:
posts
posts_pictures
posts_pictures_captions <-- Not sure about this
I know CakePHP want the tables in alphabetical order but this should in this question ignored. Please only consider plural/singular table naming.
Upvotes: 2
Views: 2759
Reputation: 1533
Cake Inflector Should do exactly what you are looking to do.
Upvotes: 2
Reputation: 324
From the cakephp book:
Model class names are singular and CamelCased. Person, BigPerson, and ReallyBigPerson are all examples of conventional model names.
Table names corresponding to CakePHP models are plural and underscored. The underlying tables for the above mentioned models would be people, big_people, and really_big_people, respectively.
You can use the utility library Inflector to check the singular/plural of words. See the Inflector for more information.
Field names with two or more words are underscored: first_name.
Foreign keys in hasMany, belongsTo or hasOne relationships are recognized by default as the (singular) name of the related table followed by _id. So if a Baker hasMany Cake, the cakes table will refer to the bakers table via a baker_id foreign key. For a table like category_types whose name contains multiple words, the foreign key would be category_type_id.
So at first, your "posts_pictures" table should be named "post_pictures". As a result, neither of the two is correct. The correct name according to the cake naming conventions is "post_picture_captions".
Upvotes: -1