CakePHP - Table 命名约定(超过一个 table)
CakePHP - Table naming conventions (over more than one table)
CakePHP 中正确的 plural/singular table 命名约定是什么。
这个:
帖子
posts_pictures
posts_picture_captions <-- 不确定
或者这个:
帖子
posts_pictures
posts_pictures_captions <-- 不确定
我知道 CakePHP 想要 table 按字母顺序排列,但这在这个问题中应该被忽略。请只考虑plural/singulartable命名。
来自 cakephp 书:
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.
所以一开始,你的 "posts_pictures" table 应该命名为 "post_pictures"。
结果,两者都不正确。根据蛋糕命名规则,正确的名字是 "post_picture_captions".
Cake Inflector 应该完全按照您的意愿去做。
CakePHP 中正确的 plural/singular table 命名约定是什么。
这个:
帖子
posts_pictures
posts_picture_captions <-- 不确定
或者这个:
帖子
posts_pictures
posts_pictures_captions <-- 不确定
我知道 CakePHP 想要 table 按字母顺序排列,但这在这个问题中应该被忽略。请只考虑plural/singulartable命名。
来自 cakephp 书:
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.
所以一开始,你的 "posts_pictures" table 应该命名为 "post_pictures"。 结果,两者都不正确。根据蛋糕命名规则,正确的名字是 "post_picture_captions".
Cake Inflector 应该完全按照您的意愿去做。